This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push: new c24eac0 Avoid explicit key cancel on Java 11 c24eac0 is described below commit c24eac03112a27f8897b7ead47d562bfa2a1ed31 Author: remm <r...@apache.org> AuthorDate: Thu Mar 12 10:53:33 2020 +0100 Avoid explicit key cancel on Java 11 NIO will internally do the work, so it's fine. The problem is abusive internal syncing during that process, but some have been removed in Java 11 and this should be enough to avoid the deadlock described in the stack trace of BZ64007. If still not resolved, then Java 14 removes even more syncs during close. --- java/org/apache/tomcat/util/net/NioEndpoint.java | 42 ++++++++++++++---------- webapps/docs/changelog.xml | 10 ++++++ 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java index 9c46678..b9cbdf5 100644 --- a/java/org/apache/tomcat/util/net/NioEndpoint.java +++ b/java/org/apache/tomcat/util/net/NioEndpoint.java @@ -50,6 +50,7 @@ import org.apache.juli.logging.LogFactory; import org.apache.tomcat.util.ExceptionUtils; import org.apache.tomcat.util.collections.SynchronizedQueue; import org.apache.tomcat.util.collections.SynchronizedStack; +import org.apache.tomcat.util.compat.JreCompat; import org.apache.tomcat.util.net.AbstractEndpoint.Handler.SocketState; import org.apache.tomcat.util.net.jsse.JSSESupport; @@ -613,25 +614,30 @@ public class NioEndpoint extends AbstractJsseEndpoint<NioChannel,SocketChannel> } public void cancelledKey(SelectionKey sk, SocketWrapperBase<NioChannel> socketWrapper) { - try { - // If is important to cancel the key first, otherwise a deadlock may occur between the - // poller select and the socket channel close which would cancel the key - // TODO: This workaround will likely be useless on Java 14+ (maybe even 11+) - // and the cancelledKey method can be removed in favor of socketWrapper.close(), see BZ 64007 - if (sk != null) { - sk.attach(null); - if (sk.isValid()) { - sk.cancel(); + if (JreCompat.isJre11Available() && socketWrapper != null) { + socketWrapper.close(); + } else { + try { + // If is important to cancel the key first, otherwise a deadlock may occur between the + // poller select and the socket channel close which would cancel the key + // This workaround is not needed on Java 11+ + // TODO: verify, if not fixed in Java 11+ then 14+ is needed, see BZ 64007 + // TODO: the cancelledKey method can be removed with Java 11 as minimum + if (sk != null) { + sk.attach(null); + if (sk.isValid()) { + sk.cancel(); + } + } + } catch (Throwable e) { + ExceptionUtils.handleThrowable(e); + if (log.isDebugEnabled()) { + log.error(sm.getString("endpoint.debug.channelCloseFail"), e); + } + } finally { + if (socketWrapper != null) { + socketWrapper.close(); } - } - } catch (Throwable e) { - ExceptionUtils.handleThrowable(e); - if (log.isDebugEnabled()) { - log.error(sm.getString("endpoint.debug.channelCloseFail"), e); - } - } finally { - if (socketWrapper != null) { - socketWrapper.close(); } } } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 92da24f..5859be2 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -45,6 +45,16 @@ issues do not "pop up" wrt. others). --> <section name="Tomcat 10.0.0-M4 (markt)" rtext="in development"> + <subsection name="Coyote"> + <changelog> + <fix> + When closing a NIO channel, avoid canceling keys as a workaround for + deadlocks when running on Java 11. Excessive internal NIO + synchronization on channel close is resolved starting with this + Java version. (remm) + </fix> + </changelog> + </subsection> </section> <section name="Tomcat 10.0.0-M3 (markt)" rtext="release in progress"> <subsection name="Coyote"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org