[SNMP4J] RuntimeException on shutdown

Frank Fock fock at agentpp.com
Thu Nov 15 22:21:32 CET 2018


Hi Mark,

The following snapshot 2.7.0 release should provide a fix for this issue:
https://snmp.app/dist/snapshot/org/snmp4j/snmp4j/2.7.0-SNAPSHOT/snmp4j-2.7.0-20181115.204944-10.jar <https://snmp.app/dist/snapshot/org/snmp4j/snmp4j/2.7.0-SNAPSHOT/snmp4j-2.7.0-20181115.204944-10.jar>

Best regards,
Frank

> On 15. Nov 2018, at 18:08, forum at friendlysnmp.org wrote:
> 
> I implemented notification 'appShutdown' as follows:
> 1. NotificationOriginatorImpl -> notify() with 'appShutdown' notification.
> 2. Snmp -> close() to release all resources.
> 3. Close application.
> 
> The result is exception (line numbers are for SNMP4J v2.6.2):
> java.lang.RuntimeException: java.net.SocketException: socket closed
>  at org.snmp4j.transport.DefaultUdpTransportMapping$ListenThread.run(DefaultUdpTransportMapping.java:455)
>  at java.lang.Thread.run(Thread.java:748)
> Caused by: java.net.SocketException: socket closed
>  at java.net.DualStackPlainDatagramSocketImpl.socketReceiveOrPeekData(Native Method)
>  at java.net.DualStackPlainDatagramSocketImpl.receive0(DualStackPlainDatagramSocketImpl.java:124)
>  at java.net.AbstractPlainDatagramSocketImpl.receive(AbstractPlainDatagramSocketImpl.java:143)
>  at java.net.DatagramSocket.receive(DatagramSocket.java:812)
>  at org.snmp4j.transport.DefaultUdpTransportMapping$ListenThread.run(DefaultUdpTransportMapping.java:397)
>  at java.lang.Thread.run(Thread.java:748)
> 
> I think the reason for the exception thrown is the 'appShutdown' notification confirmation packet comes *after* all resources are closed. The packet is processed in DefaultUdpTransportMapping.ListenThread.run() line-397 socketCopy.receive(packet).
> This method throws SocketException because the resources are closed, and the catch at line-455 re-throws RuntimeException.
> As the result DefaultUdpTransportMapping.ListenThread is not stopped and application fails to exit.
> 
> What would you suggest to fix the exception in this scenario?
> Maybe additional boolean flag in TransportMapping could be added to signal WorkerTask not to process any packets if TransportMapping is closed?
> 
> Thanks,
> Mark
> 
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> https://oosnmp.net/mailman/listinfo/snmp4j



More information about the SNMP4J mailing list