Author: markt
Date: Mon Oct 6 22:14:09 2014
New Revision: 1629776
URL: http://svn.apache.org/r1629776
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=45282
Improve shutdown of NIO receiver so that sockets are closed cleanly.
This is essentially the patch that Filip suggested in the bug report with some
additional refactoring by me.
Added:
tomcat/trunk/java/org/apache/catalina/tribes/util/ExceptionUtils.java
(with props)
Modified:
tomcat/trunk/java/org/apache/catalina/tribes/transport/nio/NioReceiver.java
tomcat/trunk/webapps/docs/changelog.xml
Modified:
tomcat/trunk/java/org/apache/catalina/tribes/transport/nio/NioReceiver.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/tribes/transport/nio/NioReceiver.java?rev=1629776&r1=1629775&r2=1629776&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/tribes/transport/nio/NioReceiver.java
(original)
+++ tomcat/trunk/java/org/apache/catalina/tribes/transport/nio/NioReceiver.java
Mon Oct 6 22:14:09 2014
@@ -37,6 +37,7 @@ import org.apache.catalina.tribes.transp
import org.apache.catalina.tribes.transport.Constants;
import org.apache.catalina.tribes.transport.ReceiverBase;
import org.apache.catalina.tribes.transport.RxTaskPool;
+import org.apache.catalina.tribes.util.ExceptionUtils;
import org.apache.catalina.tribes.util.StringManager;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
@@ -315,12 +316,7 @@ public class NioReceiver extends Receive
} catch (java.nio.channels.CancelledKeyException nx) {
log.warn(sm.getString("NioReceiver.clientDisconnect"));
} catch (Throwable t) {
- if (t instanceof ThreadDeath) {
- throw (ThreadDeath) t;
- }
- if (t instanceof VirtualMachineError) {
- throw (VirtualMachineError) t;
- }
+ ExceptionUtils.handleThrowable(t);
log.error(sm.getString("NioReceiver.requestError"), t);
}
@@ -388,6 +384,12 @@ public class NioReceiver extends Receive
} catch (ClosedSelectorException ignore){
// Ignore
}
+ try {
+ selector.selectNow();
+ } catch (Throwable t){
+ ExceptionUtils.handleThrowable(t);
+ // Ignore everything else
+ }
selector.close();
}
Added: tomcat/trunk/java/org/apache/catalina/tribes/util/ExceptionUtils.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/tribes/util/ExceptionUtils.java?rev=1629776&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/tribes/util/ExceptionUtils.java
(added)
+++ tomcat/trunk/java/org/apache/catalina/tribes/util/ExceptionUtils.java Mon
Oct 6 22:14:09 2014
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.catalina.tribes.util;
+
+/**
+ * Utilities for handling Throwables and Exceptions.
+ */
+public class ExceptionUtils {
+
+ /**
+ * Checks whether the supplied Throwable is one that needs to be
+ * rethrown and swallows all others.
+ * @param t the Throwable to check
+ */
+ public static void handleThrowable(Throwable t) {
+ if (t instanceof ThreadDeath) {
+ throw (ThreadDeath) t;
+ }
+ if (t instanceof StackOverflowError) {
+ // Swallow silently - it should be recoverable
+ return;
+ }
+ if (t instanceof VirtualMachineError) {
+ throw (VirtualMachineError) t;
+ }
+ // All other instances of Throwable will be silently swallowed
+ }
+}
Propchange:
tomcat/trunk/java/org/apache/catalina/tribes/util/ExceptionUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1629776&r1=1629775&r2=1629776&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Mon Oct 6 22:14:09 2014
@@ -147,6 +147,14 @@
</fix>
</changelog>
</subsection>
+ <subsection name="Tribes">
+ <changelog>
+ <fix>
+ <bug>45282</bug>: Improve shutdown of NIO receiver so that sockets are
+ closed cleanly. (fhanik/markt)
+ </fix>
+ </changelog>
+ </subsection>
</section>
<section name="Tomcat 8.0.14 (markt)" rtext="2014-09-29">
<subsection name="Other">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]