digitalpetri / modbus

High-performance, non-blocking, zero-buffer-copying Modbus for Java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ClosedChannelException

FreedomAlanLiu opened this issue · comments

An 'ClosedChannelException' occurred while writing, but the 'stateContext' has not changed.

ModbusTcpMaster.java:

         ch.writeAndFlush(new ModbusTcpPayload(txId, (short) unitId, request)).addListener(f -> {
                if (!f.isSuccess()) {
                    // How to fix? Whether we can?
                    /*Throwable cause = f.cause();
                    if (f.cause() instanceof ClosedChannelException) {
                        stateContext.handleEvent(ConnectionEvent.ChannelClosed);
                        cause = new RuntimeException("Channel closed!", f.cause());
                    }*/
                    PendingRequest<?> p = pendingRequests.remove(txId);
                    if (p != null) {
                        p.promise.completeExceptionally(f.cause());
                        p.timeout.cancel();
                    }
                }
            });

I've been meaning to replace the FSM with a pattern I've used successfully in other libraries and I'm pretty sure it takes care of this issue. Check out the replace-fsm branch which has the current implementation.

1.1.0 is released