From 5038dde5cdb878badaa4328e3956409917f1eaf4 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 18 Oct 2022 13:24:39 +0200 Subject: [PATCH] Run AsyncSshHandler.onOpenComplete() on event loop onOpenComplete() runs ctx.fireChannelActive(), which in turn talks to other handlers. Netty silently delays the invocation if it is called from a different thread. Make sure we run onOpenComplete() on the appropriate executor, so that the state transition and handler updates run synchronously. JIRA: NETCONF-905 Change-Id: Id8c2f4cb1e045d5d5bb446801deec341ccb27e87 Signed-off-by: Robert Varga --- .../nettyutil/handler/ssh/client/AsyncSshHandler.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandler.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandler.java index e8f128c347..5eaacb2d43 100644 --- a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandler.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandler.java @@ -182,9 +182,12 @@ public final class AsyncSshHandler extends ChannelOutboundHandlerAdapter { return; } - openFuture.addListener(future -> onOpenComplete(future, ctx)); + openFuture.addListener(future -> ctx.executor().execute(() -> onOpenComplete(future, ctx))); } + // This callback has to run on the channel's executor because it runs fireChannelActive(), which needs to be + // delivered synchronously. If we were to execute on some other thread we would end up delaying the event, + // potentially creating havoc in the pipeline. private synchronized void onOpenComplete(final OpenFuture openFuture, final ChannelHandlerContext ctx) { final var cause = openFuture.getException(); if (cause != null) { -- 2.36.6