Author: dreiss
Date: Tue Oct 7 16:03:47 2008
New Revision: 702661
URL: http://svn.apache.org/viewvc?rev=702661&view=rev
Log:
THRIFT-145. java: Make TNonblockingServer more robust against errors
TNonblockingServer was throwing a null pointer exception in certain cases.
We're not really sure what the root cause is, but this change prevents
the exception and also improves logging of certain undesirable conditions.
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=702661&r1=702660&r2=702661&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
Tue Oct 7 16:03:47 2008
@@ -318,6 +318,8 @@
} else if (key.isWritable()) {
// deal with writes
handleWrite(key);
+ } else {
+ LOGGER.log(Level.WARNING, "Unexpected state in select! " +
key.interestOps());
}
}
} catch (IOException e) {
@@ -343,9 +345,10 @@
*/
private void handleAccept() throws IOException {
SelectionKey clientKey = null;
+ TNonblockingTransport client = null;
try {
// accept the connection
- TNonblockingTransport client =
(TNonblockingTransport)serverTransport.accept();
+ client = (TNonblockingTransport)serverTransport.accept();
clientKey = client.registerSelector(selector, SelectionKey.OP_READ);
// add this key to the map
@@ -353,9 +356,10 @@
clientKey.attach(frameBuffer);
} catch (TTransportException tte) {
// something went wrong accepting.
- cleanupSelectionkey(clientKey);
LOGGER.log(Level.WARNING, "Exception trying to accept!", tte);
tte.printStackTrace();
+ if (clientKey != null) cleanupSelectionkey(clientKey);
+ if (client != null) client.close();
}
}