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; } }