Remove potential nio selector leak (#27825)
When an ESSelector is created an underlying nio selector is opened. This selector is closed by the event loop after close has been signalled by another thread. However, there is a possibility that an ESSelector is created and some exception in the startup process prevents it from ever being started (however, close will still be called). The allows the selector to leak. This commit addresses this issue by having the signalling thread close the selector if the event loop is not running when close is signalled.
This commit is contained in:
parent
c541a0c60e
commit
f33f9612a7
|
@ -177,8 +177,11 @@ public abstract class ESSelector implements Closeable {
|
|||
try {
|
||||
exitedLoop.await();
|
||||
} catch (InterruptedException e) {
|
||||
eventHandler.uncaughtException(e);
|
||||
Thread.currentThread().interrupt();
|
||||
throw new IllegalStateException("Thread was interrupted while waiting for selector to close", e);
|
||||
}
|
||||
} else if (selector.isOpen()) {
|
||||
selector.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,6 +81,12 @@ public class ESSelectorTests extends ESTestCase {
|
|||
verify(handler).selectException(ioException);
|
||||
}
|
||||
|
||||
public void testSelectorClosedIfOpenAndEventLoopNotRunning() throws IOException {
|
||||
when(rawSelector.isOpen()).thenReturn(true);
|
||||
selector.close();
|
||||
verify(rawSelector).close();
|
||||
}
|
||||
|
||||
private static class TestSelector extends ESSelector {
|
||||
|
||||
TestSelector(EventHandler eventHandler, Selector selector) throws IOException {
|
||||
|
|
Loading…
Reference in New Issue