Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force TCP reconnect when session keep-alive failure occurs #1200

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Loading