Can snmp4j cause memory leak for nmap?

hi… we’ve noticed that at times our java process crashes, and when it comes up it fails with nmap memory allocation errors, we are currently using snmp4j version 2.8.1

i’m seeing a lot of logs which i invoke on my snmp listener for connection state changes

State changed to Closed Peer address 10.11.4.208/162 143911 discarded messages
java.nio.channels.ClosedChannelException
at java.nio.channels.spi.AbstractSelectableChannel.register(AbstractSelectableChannel.java:204)
at org.snmp4j.transport.DefaultTcpTransportMapping$SocketEntry.addRegistration(DefaultTcpTransportMapping.java:450)
at org.snmp4j.transport.DefaultTcpTransportMapping$ServerThread.processPending(DefaultTcpTransportMapping.java:678)
at org.snmp4j.transport.DefaultTcpTransportMapping$ServerThread.run(DefaultTcpTransportMapping.java:904)
at java.lang.Thread.run(Thread.java:748)

You should upgrade SNMP4J to at least 2.8.7, see changes on:
https://www.snmp4j.org/CHANGES-2.x.txt

[2020-10-01] Version 2.8.5:

  • Fixed [SFJ-231]: Fixed SNMP4J TcpTransportMappings leaked socket entries on IOExceptions like BrokenPipe. Sockets are now removed and closed before TransportStateChangeEvent is fired to allow immediate reconnect.