From 59a1d29aa053f290424befca58b60611d052ceef Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Sun, 20 Apr 2014 19:47:48 +0200 Subject: [PATCH] [#2400] Not close LocalChannel during deregister() Motivation: At the moment it is not possible to deregister a LocalChannel without close it. Modification: Not close the LocalChannel during dergister Result: It will be possible in the future to deregister a LocalChannel and register it to another EventLoop --- .../main/java/io/netty/channel/local/LocalChannel.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 3b56d95ab8..89112577a3 100644 --- a/transport/src/main/java/io/netty/channel/local/LocalChannel.java +++ b/transport/src/main/java/io/netty/channel/local/LocalChannel.java @@ -155,7 +155,12 @@ public class LocalChannel extends AbstractChannel { @Override protected void doRegister() throws Exception { - if (peer != null) { + // Check if both peer and parent are non-null because this channel was created by a LocalServerChannel. + // This is needed as a peer may not be null also if a LocalChannel was connected before and + // deregistered / registered later again. + // + // See https://github.com/netty/netty/issues/2400 + if (peer != null && parent() != null) { // Store the peer in a local variable as it may be set to null if doClose() is called. // Because of this we also set registerInProgress to true as we check for this in doClose() and make sure // we delay the fireChannelInactive() to be fired after the fireChannelActive() and so keep the correct @@ -237,6 +242,7 @@ public class LocalChannel extends AbstractChannel { @Override protected void doDeregister() throws Exception { + // Just remove the shutdownHook as this Channel may be closed later or registered to another EventLoop ((SingleThreadEventExecutor) eventLoop()).removeShutdownHook(shutdownHook); }