Repository: ignite Updated Branches: refs/heads/master 91be7aff1 -> edc66af82
GridNioServer: ses can be null on close if async connect failed Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/edc66af8 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/edc66af8 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/edc66af8 Branch: refs/heads/master Commit: edc66af8221508e8d892bd9bd1e550ada9ac4a47 Parents: 91be7af Author: sboikov <[email protected]> Authored: Mon Dec 18 14:41:46 2017 +0300 Committer: sboikov <[email protected]> Committed: Mon Dec 18 14:41:46 2017 +0300 ---------------------------------------------------------------------- .../ignite/internal/util/nio/GridNioServer.java | 59 +++++++++++--------- 1 file changed, 34 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/edc66af8/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java index 1d595d2..97f6020 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java @@ -2293,7 +2293,11 @@ public class GridNioServer<T> { else if (log.isDebugEnabled()) log.debug("Failed to process selector key [ses=" + ses + ", err=" + e + ']'); - close(ses, new GridNioException(e)); + // Can be null if async connect failed. + if (ses != null) + close(ses, new GridNioException(e)); + else + closeKey(key); } } } @@ -2517,6 +2521,34 @@ public class GridNioServer<T> { } /** + * @param key Key. + */ + private void closeKey(SelectionKey key) { + // Shutdown input and output so that remote client will see correct socket close. + Socket sock = ((SocketChannel)key.channel()).socket(); + + try { + try { + sock.shutdownInput(); + } + catch (IOException ignored) { + // No-op. + } + + try { + sock.shutdownOutput(); + } + catch (IOException ignored) { + // No-op. + } + } + finally { + U.close(key, log); + U.close(sock, log); + } + } + + /** * Closes the session and all associated resources, then notifies the listener. * * @param ses Session to be closed. @@ -2536,8 +2568,6 @@ public class GridNioServer<T> { sessions.remove(ses); workerSessions.remove(ses); - SelectionKey key = ses.key(); - if (ses.setClosed()) { ses.onClosed(); @@ -2549,28 +2579,7 @@ public class GridNioServer<T> { ((DirectBuffer)ses.readBuffer()).cleaner().clean(); } - // Shutdown input and output so that remote client will see correct socket close. - Socket sock = ((SocketChannel)key.channel()).socket(); - - try { - try { - sock.shutdownInput(); - } - catch (IOException ignored) { - // No-op. - } - - try { - sock.shutdownOutput(); - } - catch (IOException ignored) { - // No-op. - } - } - finally { - U.close(key, log); - U.close(sock, log); - } + closeKey(ses.key()); if (e != null) filterChain.onExceptionCaught(ses, e);
