THRIFT-2274 java: TNonblockingServer and TThreadedSelectorServer do not close their channel selectors on exit and leak file descriptors
Patch: Thomas Kielbus
diff --git a/lib/java/src/org/apache/thrift/server/TNonblockingServer.java b/lib/java/src/org/apache/thrift/server/TNonblockingServer.java
index a6e7476..3fc8672 100644
--- a/lib/java/src/org/apache/thrift/server/TNonblockingServer.java
+++ b/lib/java/src/org/apache/thrift/server/TNonblockingServer.java
@@ -164,6 +164,11 @@
} catch (Throwable t) {
LOGGER.error("run() exiting due to uncaught error", t);
} finally {
+ try {
+ selector.close();
+ } catch (IOException e) {
+ LOGGER.error("Got an IOException while closing selector!", e);
+ }
stopped_ = true;
}
}
diff --git a/lib/java/src/org/apache/thrift/server/TThreadedSelectorServer.java b/lib/java/src/org/apache/thrift/server/TThreadedSelectorServer.java
index 8a68632..7c5ec4f 100644
--- a/lib/java/src/org/apache/thrift/server/TThreadedSelectorServer.java
+++ b/lib/java/src/org/apache/thrift/server/TThreadedSelectorServer.java
@@ -381,6 +381,11 @@
} catch (Throwable t) {
LOGGER.error("run() exiting due to uncaught error", t);
} finally {
+ try {
+ acceptSelector.close();
+ } catch (IOException e) {
+ LOGGER.error("Got an IOException while closing accept selector!", e);
+ }
// This will wake up the selector threads
TThreadedSelectorServer.this.stop();
}
@@ -547,6 +552,11 @@
} catch (Throwable t) {
LOGGER.error("run() exiting due to uncaught error", t);
} finally {
+ try {
+ selector.close();
+ } catch (IOException e) {
+ LOGGER.error("Got an IOException while closing selector!", e);
+ }
// This will wake up the accept thread and the other selector threads
TThreadedSelectorServer.this.stop();
}