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.

Thanks,
Michał

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to