Bug 62751

Summary: ajp worker's socket_connect_timeout value is handled as seconds
Product: Tomcat Connectors Reporter: TaeKyung Suk <tkstone72>
Component: mod_jkAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 1.2.44   
Target Milestone: ---   
Hardware: PC   
OS: Linux   

Description TaeKyung Suk 2018-09-21 07:48:12 UTC
Tomcat connect document explains that socket_connect_timeout is in milliseconds. But the value is handled as seconds on Linux.

test case)
I have set ajp worker's socket_connect_timeout value as 1000 (to set 1 second) and simulated pending Tomcat (by iptables DROP policy between mod_jk and Tomcat), but it waited infinitely. So I changed the value into "10" (to set 10 seconds) and worked as I expected.   

<workers.properties>
worker.server-2.socket_connect_timeout=10

<mod_jk log> : connection timeout works in 10 seconds
[Fri Sep 21 16:14:34.302 2018] [14954:140022231049984] [debug] jk_open_socket::jk_connect.c (798): trying to connect socket 14 to 150.24.200.109:8009
...
[Fri Sep 21 16:14:44.312 2018] [14954:140022231049984] [info] jk_open_socket::jk_connect.c (816): connect to 150.24.200.109:8009 failed (errno=115)
[Fri Sep 21 16:14:44.312 2018] [14954:140022231049984] [info] ajp_connect_to_endpoint::jk_ajp_common.c (1065): (server-2) Failed opening socket to (150.24.200.109:8009) (errno=115)
...
[Fri Sep 21 16:14:54.423 2018] [14954:140022231049984] [info] jk_open_socket::jk_connect.c (816): connect to 150.24.200.109:8009 failed (errno=115)
[Fri Sep 21 16:14:54.423 2018] [14954:140022231049984] [info] ajp_connect_to_endpoint::jk_ajp_common.c (1065): (server-2) Failed opening socket to (150.24.200.109:8009) (errno=115)
[Fri Sep 21 16:14:54.423 2018] [14954:140022231049984] [error] ajp_send_request::jk_ajp_common.c (1725): (server-2) connecting to backend failed. Tomcat is probably not started or is listening on the wrong port (errno=115)
...

<jk_connect.c>
...
line 277 => rc = poll(&pfd, 1, timeout * 1000); // timeout is handled as seconds
Comment 1 TaeKyung Suk 2018-09-21 07:51:45 UTC
jk_connect.c handles socket_connect_timeout value as milliseconds on Windows.
<jk_connect.c>
line 206, 207
        tv.tv_sec = timeout / 1000;
        tv.tv_usec = (timeout % 1000) * 1000;
Comment 2 Rainer Jung 2018-09-24 09:39:49 UTC
Thanks for your report and analysis.
This was a regression in version 1.2.44 on platforms that are non-Windows and do support poll().
The following fix was committed in r1841817 and will be part of version 1.2.46:

Index: native/common/jk_connect.c
===================================================================
--- native/common/jk_connect.c  (revision 1841810)
+++ native/common/jk_connect.c  (working copy)
@@ -274,7 +274,7 @@
         socklen_t rclen = (socklen_t)sizeof(rc);
         pfd.fd = sd;
         pfd.events = POLLOUT;
-        rc = poll(&pfd, 1, timeout * 1000);
+        rc = poll(&pfd, 1, timeout);
         if (rc <= 0) {
             /* Save errno */
             int err = errno;

Regards,

Rainer