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 143911 discarded messages
at java.nio.channels.spi.AbstractSelectableChannel.register(
at org.snmp4j.transport.DefaultTcpTransportMapping$SocketEntry.addRegistration(
at org.snmp4j.transport.DefaultTcpTransportMapping$ServerThread.processPending(
at org.snmp4j.transport.DefaultTcpTransportMapping$

You should upgrade SNMP4J to at least 2.8.7, see changes on:

[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.