You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2020/10/28 09:48:40 UTC

[tomcat] branch 9.0.x updated: Add dedicated handling and warn for a null socket channel

This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 99c52a2  Add dedicated handling and warn for a null socket channel
99c52a2 is described below

commit 99c52a2ef6040b6d5a7f96479ef278ad7d1e7b64
Author: remm <re...@apache.org>
AuthorDate: Wed Oct 28 10:46:43 2020 +0100

    Add dedicated handling and warn for a null socket channel
    
    The cause of the null socket channel is unknown at this time.
---
 java/org/apache/tomcat/util/net/LocalStrings.properties |  1 +
 java/org/apache/tomcat/util/net/NioEndpoint.java        | 14 ++++++++++----
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/java/org/apache/tomcat/util/net/LocalStrings.properties b/java/org/apache/tomcat/util/net/LocalStrings.properties
index 10daeb0..696f882 100644
--- a/java/org/apache/tomcat/util/net/LocalStrings.properties
+++ b/java/org/apache/tomcat/util/net/LocalStrings.properties
@@ -96,6 +96,7 @@ endpoint.launch.fail=Failed to launch new runnable
 endpoint.nio.keyProcessingError=Error processing selection key
 endpoint.nio.latchMustBeZero=Latch must be at count zero or null
 endpoint.nio.nullLatch=Latch cannot be null
+endpoint.nio.nullSocketChannel=Invalid null socket channel while processing poller event
 endpoint.nio.pollerEventError=Error processing poller event
 endpoint.nio.registerFail=Failed to register socket with selector from poller
 endpoint.nio.selectorCloseFail=Failed to close selector when closing the poller
diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java
index 827fa08..d960d39 100644
--- a/java/org/apache/tomcat/util/net/NioEndpoint.java
+++ b/java/org/apache/tomcat/util/net/NioEndpoint.java
@@ -602,16 +602,22 @@ public class NioEndpoint extends AbstractJsseEndpoint<NioChannel,SocketChannel>
             for (int i = 0, size = events.size(); i < size && (pe = events.poll()) != null; i++ ) {
                 result = true;
                 NioChannel channel = pe.getSocket();
+                SocketChannel sc = channel.getIOChannel();
                 NioSocketWrapper socketWrapper = channel.getSocketWrapper();
                 int interestOps = pe.getInterestOps();
-                if (interestOps == OP_REGISTER) {
+                if (sc == null) {
+                    log.warn(sm.getString("endpoint.nio.nullSocketChannel"));
+                    if (socketWrapper != null) {
+                        socketWrapper.close();
+                    }
+                } else if (interestOps == OP_REGISTER) {
                     try {
-                        channel.getIOChannel().register(getSelector(), SelectionKey.OP_READ, socketWrapper);
+                        sc.register(getSelector(), SelectionKey.OP_READ, socketWrapper);
                     } catch (Exception x) {
                         log.error(sm.getString("endpoint.nio.registerFail"), x);
                     }
                 } else {
-                    final SelectionKey key = channel.getIOChannel().keyFor(getSelector());
+                    final SelectionKey key = sc.keyFor(getSelector());
                     if (key == null) {
                         // The key was cancelled (e.g. due to socket closure)
                         // and removed from the selector while it was being
@@ -631,7 +637,7 @@ public class NioEndpoint extends AbstractJsseEndpoint<NioChannel,SocketChannel>
                                 cancelledKey(key, socketWrapper);
                             }
                         } else {
-                            cancelledKey(key, null);
+                            cancelledKey(key, socketWrapper);
                         }
                     }
                 }


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org