From 77d4222db5794bb0ffe99065cc556c09e5aec68d Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Sun, 25 Aug 2013 21:22:53 +0200 Subject: [PATCH] [#1777] Use correct Thread when close per channel --- .../io/netty/channel/local/LocalChannel.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/transport/src/main/java/io/netty/channel/local/LocalChannel.java b/transport/src/main/java/io/netty/channel/local/LocalChannel.java index 7d558db7e4..6b067d476c 100644 --- a/transport/src/main/java/io/netty/channel/local/LocalChannel.java +++ b/transport/src/main/java/io/netty/channel/local/LocalChannel.java @@ -198,9 +198,21 @@ public class LocalChannel extends AbstractChannel { state = 3; } - LocalChannel peer = this.peer; + final LocalChannel peer = this.peer; if (peer != null && peer.isActive()) { - peer.unsafe().close(unsafe().voidPromise()); + // Need to execute the close in the correct EventLoop + // See https://github.com/netty/netty/issues/1777 + EventLoop eventLoop = peer.eventLoop(); + if (eventLoop.inEventLoop()) { + peer.unsafe().close(unsafe().voidPromise()); + } else { + peer.eventLoop().execute(new Runnable() { + @Override + public void run() { + peer.unsafe().close(unsafe().voidPromise()); + } + }); + } this.peer = null; } }