Skip to content

Commit

Permalink
Force TCP reconnect when session keep-alive failure occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinherron committed Jan 10, 2024
1 parent f1ce134 commit 1fb7e5d
Showing 1 changed file with 14 additions and 1 deletion.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 the Eclipse Milo Authors
* Copyright (c) 2024 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -31,6 +31,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Streams;
import com.google.common.primitives.Bytes;
import io.netty.channel.Channel;
import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
import org.eclipse.milo.opcua.sdk.client.OpcUaSession;
import org.eclipse.milo.opcua.sdk.client.api.ServiceFaultListener;
Expand Down Expand Up @@ -651,6 +652,18 @@ public void onStateTransition(
);

ctx.fireEvent(new Event.KeepAliveFailure());

// Close the underlying channel to force a reconnect.
// This is useful if the server has gone offline in an "unclean"
// manner to avoid having to wait for the underlying TCP stack's keep
// alive to kick in.
UaTransport transport = client.getStackClient().getTransport();
if (transport instanceof OpcTcpTransport) {
Channel channel = ((OpcTcpTransport) transport).channel().getNow(null);
if (channel != null) {
channel.close();
}
}
} else {
LOGGER.debug(
"[{}] Keep Alive failureCount={}",
Expand Down

0 comments on commit 1fb7e5d

Please sign in to comment.