digitalpetri / modbus

Modbus TCP, Modbus RTU/TCP, and Modbus RTU/Serial for Java 17+.
Eclipse Public License 2.0
654 stars 222 forks source link

ClosedChannelException #3

Closed FreedomAlanLiu closed 7 years ago

FreedomAlanLiu commented 8 years ago

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();
                    }
                }
            });
kevinherron commented 8 years ago

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.

kevinherron commented 7 years ago

1.1.0 is released