Bug 63568 - Allow keeping tcpNoDelay untouched (default)
Summary: Allow keeping tcpNoDelay untouched (default)
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 9
Classification: Unclassified
Component: Catalina (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: -----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-07-16 20:36 UTC by František Kučera <xkucf03/>
Modified: 2019-07-19 08:54 UTC (History)
0 users



Attachments
hotfix to enable Tomcat listening on an inherited unix domain socket (826 bytes, patch)
2019-07-16 20:36 UTC, František Kučera <xkucf03/>
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description František Kučera <xkucf03/> 2019-07-16 20:36:22 UTC
Created attachment 36661 [details]
hotfix to enable Tomcat listening on an inherited unix domain socket

Hello,

I got this error when new HTTP request comes:

14-Jul-2019 18:18:39.296 SEVERE [http-nio-8080-Acceptor] org.apache.tomcat.util.net.NioEndpoint.setSocketOptions Error setting socket options
        java.net.SocketException: Operace není podporována
                at sun.nio.ch.Net.setIntOption0(Native Method)
                at sun.nio.ch.Net.setSocketOption(Net.java:334)
                at sun.nio.ch.SocketChannelImpl.setOption(SocketChannelImpl.java:190)
                at sun.nio.ch.SocketAdaptor.setBooleanOption(SocketAdaptor.java:271)
                at sun.nio.ch.SocketAdaptor.setTcpNoDelay(SocketAdaptor.java:306)
                at org.apache.tomcat.util.net.SocketProperties.setProperties(SocketProperties.java:204)
                at org.apache.tomcat.util.net.NioEndpoint.setSocketOptions(NioEndpoint.java:401)
                at org.apache.tomcat.util.net.NioEndpoint.setSocketOptions(NioEndpoint.java:73)
                at org.apache.tomcat.util.net.Acceptor.run(Acceptor.java:115)
                at java.lang.Thread.run(Thread.java:748)

do not panic, this does not happen in normal conditions - my setup is kind of special. Given socket does not support the tcpNoDelay option, so it throws an exception. To get rid of it, I patched the Tomcat's source code (see attachment, it patches the latest git version).

I am looking for a more clean solution that could be merged in the official sources. I suggest adding a third option in the tcpNoDelay configuration <https://tomcat.apache.org/tomcat-9.0-doc/config/http.html> like "default" or "null" besides the "true" and "false" (i.e. convert some booleans to Booleans in the source code and allow the null value) which will cause that setTcpNoDelay() method will not be called on new incomming connections/sockets.

Please confirm whether this is a good solution – I will then write a new patch.

Original mailing list thread: <http://tomcat.10.x6.nabble.com/Allow-keeping-tcpNoDelay-untouched-default-td5087592.html>

Context: I am interested in making applications listen on unix domain sockets instead of TCP ones (e.g. Jetty can work this way) and especially in listening on sockets inherited from parent process (the "useInheritedChannel" in Tomcat's Connector configuration). And unix domain socket has no tcpNoDelay option obviously.

Franta
Comment 1 Remy Maucherat 2019-07-18 21:10:42 UTC
Since it's probably not a good idea to change the default behavior at this point, the "hotfix" proposed does not sound that bad.
Comment 2 Remy Maucherat 2019-07-19 08:33:43 UTC
I chose to use the patch. This will be in 8.5.44 and 9.0.23.
Comment 3 František Kučera <xkucf03/> 2019-07-19 08:54:43 UTC
Thanks.

If anyone want to test it, here is config for systemd: <https://blog.frantovo.cz/c/372/#toc_14> or a simple loader written in C: <https://blog.frantovo.cz/c/372/#toc_12> which makes Tomcat listen on an inherited unix domain socket. Integration with Apache HTTPD is also easy - like:

ProxyPass unix:/run/tomcat|http://localhost/