You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by dr...@apache.org on 2008/07/14 01:15:55 UTC

svn commit: r676456 - /incubator/thrift/trunk/lib/java/src/com/facebook/thrift/server/TNonblockingServer.java

Author: dreiss
Date: Sun Jul 13 16:15:55 2008
New Revision: 676456

URL: http://svn.apache.org/viewvc?rev=676456&view=rev
Log:
java: Close broken connections [THRIFT-73]

Fixes a bug where TNonblockingServer (and by extension THsHaServer) could
permanently lose track of client connections if the message on-wire was
malformed. If the client sends a bad message now, the server will close the
transport at its earliest convenience.

Modified:
    incubator/thrift/trunk/lib/java/src/com/facebook/thrift/server/TNonblockingServer.java

Modified: incubator/thrift/trunk/lib/java/src/com/facebook/thrift/server/TNonblockingServer.java
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/src/com/facebook/thrift/server/TNonblockingServer.java?rev=676456&r1=676455&r2=676456&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/java/src/com/facebook/thrift/server/TNonblockingServer.java (original)
+++ incubator/thrift/trunk/lib/java/src/com/facebook/thrift/server/TNonblockingServer.java Sun Jul 13 16:15:55 2008
@@ -423,6 +423,8 @@
     private static final int WRITING = 6;
     // another thread wants this framebuffer to go back to reading
     private static final int AWAITING_REGISTER_READ = 7;
+    // we want our transport and selection key invalidated in the selector thread
+    private static final int AWAITING_CLOSE = 8;
 
     //
     // Instance variables
@@ -548,6 +550,9 @@
         state_ = WRITING;
       } else if (state_ == AWAITING_REGISTER_READ) {
         prepareRead();
+      } else if (state_ == AWAITING_CLOSE){
+        close();
+        selectionKey_.cancel();
       } else {
         LOGGER.severe(
           "changeSelectInterest was called, but state is invalid ("
@@ -607,9 +612,15 @@
       try {
         processorFactory_.getProcessor(inTrans).process(inProt, outProt);
         responseReady();
+        return;
       } catch (TException te) {
         LOGGER.log(Level.WARNING, "Exception while invoking!", te);
+      } catch (Exception e) {
+        LOGGER.log(Level.SEVERE, "Unexpected exception while invoking!", e);
       }
+      // This will only be reached when there is an exception.
+      state_ = AWAITING_CLOSE;
+      requestSelectInterestChange();
     }
 
     /**