java-coap icon indicating copy to clipboard operation
java-coap copied to clipboard

Socket Closed when stop()

Open KeithLaiKB opened this issue 4 years ago • 3 comments
trafficstars

when I try to test the example java-coap/coap-core/src/test/java/protocolTests/ClientServerTest.java (https://github.com/PelionIoT/java-coap/blob/master/coap-core/src/test/java/protocolTests/ClientServerTest.java)

case: when server.stop() or client.stop(), the console would show "java.net.SocketException: socket closed"

process: when I traced this process, I found it sources from DatagramSocketTransport.stop() method and LOGGER.error(e.getMessage(), e); in the method, the code line about "TransportExecutors.shutdown(readingWorker);" in this method couldn't run.

Should we deal with it or need to ignore it.

KeithLaiKB avatar Oct 05 '21 01:10 KeithLaiKB

when I tried to change the "Socket closed" to "socket closed" in com.mbed.coap.transport.udp.DatagramSocketTransport, it seems that it could solve this problem, but I don't know whether this change is what the contributor want.

source: com.mbed.coap.transport.udp.DatagramSocketTransport

if (!ex.getMessage().startsWith("Socket closed")) { LOGGER.warn(ex.getMessage(), ex); }

KeithLaiKB avatar Jan 06 '22 22:01 KeithLaiKB

Hi @KeithLaiKB,

How about checking against "ocket closed"? This was we would cover both cases. Please feel free to make PR.

szysas avatar Jan 07 '22 07:01 szysas

Hi @KeithLaiKB,

How about checking against "ocket closed"? This was we would cover both cases. Please feel free to make PR.

I think it could be ok if (!ex.getMessage().contains("ocket closed")), it might work, but it might also be the potential risk in the future. in my opinion, if (!ex.getMessage().startsWith("Socket closed")&& !ex.getMessage().startsWith("socket closed")) would be better.

KeithLaiKB avatar Jan 24 '22 02:01 KeithLaiKB