From 386b47d03ff01a9b1d7dd3fe1873b09f9429c945 Mon Sep 17 00:00:00 2001 From: fhanik Date: Mon, 30 Oct 2006 17:47:26 +0000 Subject: [PATCH] Fixed null pointer exception on comet socket timeout git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@469207 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/tomcat/util/net/NioEndpoint.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java index 10c2deb94..fc47164de 100644 --- a/java/org/apache/tomcat/util/net/NioEndpoint.java +++ b/java/org/apache/tomcat/util/net/NioEndpoint.java @@ -1138,13 +1138,14 @@ public class NioEndpoint { public void cancelledKey(SelectionKey key, SocketStatus status) { try { KeyAttachment ka = (KeyAttachment) key.attachment(); - if ( key.isValid() ) key.cancel(); - if (ka != null && ka.getComet()) processSocket( ka.getChannel(), status); - // FIXME: closing in all these cases is a bit mean. IMO, it should leave it - // to the worker (or executor) depending on what the request processor - // returns - if ( key.channel().isOpen() ) key.channel().close(); - key.attach(null); + if (ka != null && ka.getComet()) { + //the comet event takes care of clean up + processSocket(ka.getChannel(), status); + }else { + if (key.isValid()) key.cancel(); + if (key.channel().isOpen()) key.channel().close(); + key.attach(null); + } } catch (Throwable e) { if ( log.isDebugEnabled() ) log.error("",e); // Ignore @@ -1257,6 +1258,8 @@ public class NioEndpoint { long timeout = (ka.getTimeout()==-1)?((long) socketProperties.getSoTimeout()):(ka.getTimeout()); boolean isTimedout = delta > timeout; if (isTimedout) { + key.interestOps(0); + ka.interestOps(0); //avoid duplicate timeout calls cancelledKey(key, SocketStatus.TIMEOUT); } else { long nextTime = now+(timeout-delta); -- 2.11.0