Skip to content

Can't connect to PLC over VPN #1339

@JessevGool

Description

@JessevGool

Describe the bug
I am unable to connect to a PLC that I am connected to over a VPN. I can connect to the PLC using different libraries just fine but Milo is throwing a timeout.
I am using the following code:

public class Main {
    public static void main(String[] args)  throws Exception{
        OpcUaClient client = OpcUaClient.create(
                "opc.tcp://192.168.30.5:4840",
                endpoints -> endpoints.stream().findFirst(),
                configBuilder -> configBuilder
                        .setRequestTimeout(UInteger.valueOf(10000))
                        .setConnectTimeout(UInteger.valueOf(10000))
                        .build()
        );
        try {
            client.connect().get();
        } catch (Exception e) {
            if (e.getCause() instanceof UaException) {
                UaException uaException = (UaException) e.getCause();
                System.out.println("Failed to connect. Status: " + uaException.getStatusCode());
                System.out.println("Error message: " + uaException.getMessage());
            }
            e.printStackTrace();
        }


        UaVariableNode node = client.getAddressSpace().getVariableNode(Identifiers.Server_ServerStatus_StartTime);
        DataValue value = node.readValue();

        System.out.printf("StartTime=%s", value.getValue().getValue().toString());
    }
}

Logs and Packet Captures
The error being thrown

[main] INFO org.eclipse.milo.opcua.sdk.client.OpcUaClient - Java version: 17.0.12
[main] INFO org.eclipse.milo.opcua.sdk.client.OpcUaClient - Eclipse Milo OPC UA Stack version: 0.6.13
[main] INFO org.eclipse.milo.opcua.sdk.client.OpcUaClient - Eclipse Milo OPC UA Client SDK version: 0.6.13
Failed to connect. Status: StatusCode{name=Bad_Timeout, value=0x800A0000, quality=bad}
Error message: io.netty.channel.ConnectTimeoutException: connection timed out after 10000 ms: /50.50.50.1:4840
java.util.concurrent.ExecutionException: UaException: status=Bad_Timeout, message=io.netty.channel.ConnectTimeoutException: connection timed out after 10000 ms: /50.50.50.1:4840
	at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396)
	at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2073)
	at org.example.Main.main(Main.java:35)
Caused by: UaException: status=Bad_Timeout, message=io.netty.channel.ConnectTimeoutException: connection timed out after 10000 ms: /50.50.50.1:4840
	at org.eclipse.milo.opcua.stack.client.transport.uasc.ClientChannelFsm$ClientChannelActions.lambda$connect$0(ClientChannelFsm.java:126)
	at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:590)
	at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:583)
	at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:559)
	at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:492)
	at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:636)
	at io.netty.util.concurrent.DefaultPromise.setFailure0(DefaultPromise.java:629)
	at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:118)
	at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:264)
	at io.netty.util.concurrent.PromiseTask.runTask(PromiseTask.java:98)
	at io.netty.util.concurrent.ScheduledFutureTask.run(ScheduledFutureTask.java:153)
	at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:173)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:166)
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:569)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: io.netty.channel.ConnectTimeoutException: connection timed out after 10000 ms: /50.50.50.1:4840
	at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:263)
	... 9 more
Exception in thread "main" UaException: status=Bad_SessionClosed, message=The session was closed by the client.
	at org.eclipse.milo.opcua.sdk.client.session.SessionFsmFactory.lambda$null$1(SessionFsmFactory.java:164)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:840)

Additional context
I am using the latest version of Milo, the error doesn't occur when I try to connect to the public server. I also noted that it says 50.50.50.1:4840 in the error and I'm wondering where that is coming from

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions