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

java.util.concurrent.TimeoutException: senderContext=0 timed out waiting 3000ms for response #80

Open
WendelYu opened this issue Jan 14, 2025 · 0 comments

Comments

@WendelYu
Copy link

I have a scheduled task that calls readAll every second, and then my logic invokes the read/write method;
After two days of running the code, there is an error, is there a problem with my usage?
java.util.concurrent.ExecutionException: java.util.concurrent.TimeoutException: senderContext=0 timed out waiting 3000ms for response
at java.util.concurrent.CompletableFuture.reportGet(Unknown Source) ~[na:1.8.0_231]
at java.util.concurrent.CompletableFuture.get(Unknown Source) ~[na:1.8.0_231]
at com.sinstry.ethernet.utils.EtherNetUtils.writeIntWithException(EtherNetUtils.java:341) ~[sinstry-ethernet-1.0.0-SNAPSHOT.jar!/:1.0.0-SNAPSHOT]
at com.sinstry.ethernet.utils.EtherNetUtils.writeIntTag(EtherNetUtils.java:317) ~[sinstry-ethernet-1.0.0-SNAPSHOT.jar!/:1.0.0-SNAPSHOT]
at com.sinstry.station.socket.CarQueueSocketHandler.updateNumber(CarQueueSocketHandler.java:199) [classes!/:1.0.0-SNAPSHOT]
at com.sinstry.station.socket.CarQueueSocketHandler.broadcast(CarQueueSocketHandler.java:85) [classes!/:1.0.0-SNAPSHOT]
at com.sinstry.station.socket.AbstractWebSocketHandler.onOpen(AbstractWebSocketHandler.java:43) [classes!/:1.0.0-SNAPSHOT]
at sun.reflect.GeneratedMethodAccessor175.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_231]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_231]
at org.apache.tomcat.websocket.pojo.PojoEndpointBase.doOnOpen(PojoEndpointBase.java:65) [tomcat-embed-websocket-9.0.45.jar!/:na]
at org.apache.tomcat.websocket.pojo.PojoEndpointServer.onOpen(PojoEndpointServer.java:64) [tomcat-embed-websocket-9.0.45.jar!/:na]
at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler.init(WsHttpUpgradeHandler.java:135) [tomcat-embed-websocket-9.0.45.jar!/:na]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:940) [tomcat-embed-core-9.0.45.jar!/:na]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1707) [tomcat-embed-core-9.0.45.jar!/:na]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.45.jar!/:na]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_231]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_231]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.45.jar!/:na]
at java.lang.Thread.run(Unknown Source) [na:1.8.0_231]
Caused by: java.util.concurrent.TimeoutException: senderContext=0 timed out waiting 3000ms for response
at com.digitalpetri.enip.EtherNetIpClient.lambda$writeCommand$5(EtherNetIpClient.java:173) ~[enip-client-1.4.1.jar!/:na]
at io.netty.util.HashedWheelTimer$HashedWheelTimeout.expire(HashedWheelTimer.java:672) ~[netty-common-4.1.63.Final.jar!/:4.1.63.Final]
at io.netty.util.HashedWheelTimer$HashedWheelBucket.expireTimeouts(HashedWheelTimer.java:747) ~[netty-common-4.1.63.Final.jar!/:4.1.63.Final]
at io.netty.util.HashedWheelTimer$Worker.run(HashedWheelTimer.java:472) ~[netty-common-4.1.63.Final.jar!/:4.1.63.Final]
... 1 common frames omitted

Here's my code;

public class PLCConnectionManager {

private static CipClient readclient;

private static CipConnectionPool readpool;


static {
    EtherNetIpClientConfig config = EtherNetIpClientConfig.builder("192.168.1.2")
            .setSerialNumber(0x00)
            .setVendorId(0x00)
            .setTimeout(Duration.ofSeconds(2))
            .build();
    // backplane, slot 0
    EPath.PaddedEPath connectionPath = new EPath.PaddedEPath(
            new PortSegment(1, new byte[]{(byte) 0}));
    readclient = new CipClient(config, connectionPath);
    readclient.connect().join();
    readpool = new CipConnectionPool(5, readclient, connectionPath, 500);


}
public static CipConnectionPool getCipPool(){
    return readpool;
}

public static CipClient getCipClient(){
    return readclient;
}


@PreDestroy
public static void shutdown(){
    if (readclient != null){
        readclient.disconnect().join();
    }
    EtherNetIpShared.releaseSharedResources();
}

}

public void readAll() throws Exception {
    
    CipConnectionPool pool = PLCConnectionTaskReadManager.getCipPool();
    CipClient client = PLCConnectionTaskReadManager.getCipClient();
    List<String> typeList = new ArrayList<>();
    typeList.add("type1");
    typeList.add("type2");
    typeList.add("type3");
    List<Variable> variables = variableDao.findByTypeIn(typeList);
    for (Variable variable : variables) {
        pool.acquire().thenAccept(connection -> {
            if (connection != null) {
                EPath.PaddedEPath requestPath = new EPath.PaddedEPath(new DataSegment.AnsiDataSegment(variable.getName()));
                ReadTagService readTagService = new ReadTagService(requestPath, 1);
                CompletableFuture<ByteBuf> f = client.invokeConnected(connection.getO2tConnectionId(), readTagService);
                f.whenComplete((data, ex2) -> {
                    if (data != null) {
                        if (variable.getDataType().equals(VariableDataTypeHandler.DcVariableDataType.INT.getValue())) {
                            BigInteger bigInteger = new BigInteger(ByteBufUtil.hexDump(data, 2, 1), 16);
                            Integer value = bigInteger.intValue();
                            if (value != null) {
                                // Data processing
                            }
                        }
                    } else {
                        ex2.printStackTrace();
                    }
                    pool.release(connection);
                });
            }
        });
    }
}

public void writeIntTag(String tag , int value) throws ExecutionException, InterruptedException {
CipConnectionPool pool = PLCConnectionTaskReadManager.getCipPool();
CipClient client = PLCConnectionTaskReadManager.getCipClient();

    // the tag we'll use as an example
    EPath.PaddedEPath requestPath = new EPath.PaddedEPath(new DataSegment.AnsiDataSegment(tag));
    ByteBuf buffer = Unpooled.buffer().order(ByteOrder.LITTLE_ENDIAN);
    buffer.writeInt(value);

    WriteTagService writeTagService = new WriteTagService(
            requestPath,
            false,
            CipDataType.INT.getCode(),
            buffer
    );

    pool.acquire().thenAccept(connection -> {
        CompletableFuture<Void> f = client.invokeConnected(
                connection.getO2tConnectionId(), writeTagService);

        f.whenComplete((v, ex) -> {
            if (ex != null) {
                ex.printStackTrace();
            } else {
                // System.out.println("WriteTagService completed.");
            }
            pool.release(connection);
        });
    });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant