From db65e3dd68ad1a335996d319bee6c923974872f1 Mon Sep 17 00:00:00 2001 From: David Reiss Date: Sun, 13 Jul 2008 23:15:55 +0000 Subject: [PATCH] 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. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@676456 13f79535-47bb-0310-9956-ffa450edef68 --- .../facebook/thrift/server/TNonblockingServer.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/java/src/com/facebook/thrift/server/TNonblockingServer.java b/lib/java/src/com/facebook/thrift/server/TNonblockingServer.java index d09ec67a..1e1284f5 100644 --- a/lib/java/src/com/facebook/thrift/server/TNonblockingServer.java +++ b/lib/java/src/com/facebook/thrift/server/TNonblockingServer.java @@ -423,6 +423,8 @@ public class TNonblockingServer extends TServer { 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 @@ public class TNonblockingServer extends TServer { 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 @@ public class TNonblockingServer extends TServer { 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(); } /** -- 2.17.1