> On Feb 23, 2024, at 10:18, Michał Szymborski <michalszymbor...@gmail.com> 
> wrote:
> 
> Hi, I've encountered an issue where the acceptor doesn't stop cleanly when 
> shutting Tomcat down on some machines. I'm using tomcat-embed-core 10.1.19, 
> I've tested it on Ubuntu 22.04 and MacOs Sonoma 14.3.1.
> 
> Here is a minimum reproducible example (also available here 
> https://github.com/lared/tomcat-acceptor-not-stopping-cleanly):
> 
> ```
> import org.apache.catalina.LifecycleException;
> import org.apache.catalina.connector.Connector;
> import org.apache.catalina.startup.Tomcat;
> 
> class SlowStop {
>    public static void main(String[] args) throws LifecycleException {
>        var connector = new 
> Connector("org.apache.coyote.http11.Http11NioProtocol");
>        connector.setPort(0);
> 
>        Tomcat tomcat = new Tomcat();
>        tomcat.getService().addConnector(connector);
> 
>        tomcat.start();
>        tomcat.stop();
>    }
> }
> ```
> 
> 
> Whenever I run this code on setup as listed above, shutdown of the 
> ProtocolHandler times out when trying to stop the acceptor. Here is an 
> excerpt from logs:
> 
> ```
> Feb 23, 2024 4:42:34 PM org.apache.coyote.AbstractProtocol stop
> INFO: Stopping ProtocolHandler ["http-nio-8080"]
> Feb 23, 2024 4:42:44 PM org.apache.tomcat.util.net.Acceptor stop
> WARNING: The acceptor thread [http-nio-8080-Acceptor] did not stop cleanly
> ```
> 
> This can be traced down to `NioEndpoint` stopping, particularly stopping the 
> acceptor:
> 
> https://github.com/apache/tomcat/blob/10.1.x/java/org/apache/tomcat/util/net/NioEndpoint.java#L308
> 
> https://github.com/apache/tomcat/blob/10.1.x/java/org/apache/tomcat/util/net/Acceptor.java#L180
> 
> 
> This issue is not reproducible on every setup (see github actions run on the 
> linked repo), and it only affects NIO - NIO2 works as expected.
> 
> I've encountered this issue when Spring Boot got upgraded to 3.2.x line 
> (switch from Tomcat 9 to 10.1.x).
> 
> Could you please advise me where I can go from here? This is particularly 
> annoying in our testing setup, where timely teardown of the Tomcat is very 
> appreciated (even if disruptive).
> 
> Unfortunately I'm a fair bit out of my depth here when it comes to 
> troubleshooting this further. It is rather surprising that even though people 
> were not able to reproduce it on some of their setups (like MacOs 13.6.4), 
> but I actually was able to reproduce it on two machines I own, my colleagues 
> at work have the same issue.


I could not reproduce the error in several hundred executions of your test 
program on my M1 MacBook Pro (Sonoma 14.3.1, OpenJDK 21.0.1) using just command 
line execution:

chuck@Chuck-MacBookPro JavaTest > java -version
openjdk version "21.0.1" 2023-10-17 LTS
OpenJDK Runtime Environment Temurin-21.0.1+12 (build 21.0.1+12-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.1+12 (build 21.0.1+12-LTS, mixed mode)
chuck@Chuck-MacBookPro JavaTest > java -cp `find 
~/Downloads/apache-tomcat-10.1.19-embed -name '*.jar' | tr '\n' ':' | sed 
's/:$/:./'` SlowStop
Feb 25, 2024 8:55:54 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-auto-1"]
Feb 25, 2024 8:55:54 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service [Tomcat]
Feb 25, 2024 8:55:54 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-auto-1-56406"]
Feb 25, 2024 8:55:54 AM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-nio-auto-1-56406"]
Feb 25, 2024 8:55:54 AM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service [Tomcat]
Feb 25, 2024 8:55:54 AM org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["http-nio-auto-1-56406"]

Any chance the problem has something to do with your gradle environment?

  - Chuck

Reply via email to