The jni native method poll() in poll.c does not check if the socket has no timeout (i.e. it does not check if max_ttl is negative) before adjusting the timeout passed to apr_pollset_poll(). The timeout passed to apr_pollset_poll() is in the variable 'ptime'. The current code sets ptime to zero when there is a valid timeout (usually 2000ms) and no socket timeout (usually -1000). These values are common because AprEndpoint.java defaults to pollTime=2000 ms and soTimeout=-1 sec (which gets adjusted to -1000 ms). When a zero timeout is passed to apr_pollset_poll(), it is passed along to the native select() as a zero timeval which causes select() to return immediately instead of blocking. A negative value should be passed to apr_pollset_poll() for an infinite timeout, but I don't think that's what we want here. The observed result is 100% cpu use when Tomcat is idle because calls to poll() are made continuously. These calls return immediately. The solution is to recognize when max_ttl is negative, and if so; do not use it to adjust the 'ptime' variable passed as an argument to poll(). Here is a patch for http://svn.apache.org/repos/asf/tomcat/connectors/trunk/. Index: jni/native/src/poll.c =================================================================== --- jni/native/src/poll.c (revision 446772) +++ jni/native/src/poll.c (working copy) @@ -263,7 +263,7 @@ /* Find the minimum timeout */ for (i = 0; i < p->nelts; i++) { apr_interval_time_t t = now - p->socket_ttl[i]; - if (t >= p->max_ttl) { + if (p->max_ttl > 0 && t >= p->max_ttl) { ptime = 0; break; }
(In reply to comment #0) The patch in my original comment is incorrect. It does not preserve the timeout when there is no socket timeout. Apologies! Here is a corrected patch: Index: jni/native/src/poll.c =================================================================== --- jni/native/src/poll.c (revision 446772) +++ jni/native/src/poll.c (working copy) @@ -263,13 +263,16 @@ /* Find the minimum timeout */ for (i = 0; i < p->nelts; i++) { apr_interval_time_t t = now - p->socket_ttl[i]; - if (t >= p->max_ttl) { - ptime = 0; - break; - } - else { - ptime = TCN_MIN(p->max_ttl - t, ptime); - } + if (p->max_ttl > 0) + { + if (t >= p->max_ttl) { + ptime = 0; + break; + } + else { + ptime = TCN_MIN(p->max_ttl - t, ptime); + } + } } } for (;;) {
*** Bug 40606 has been marked as a duplicate of this bug. ***
Fixed in the SVN trunk, although the patch aplied is slightly different.
Removing Native:JK component, because this issue belongs to tcnative, which seems to not have a component value. Also moving from resolved to closed.