[SNMP4J] How to cancel a async request when the Response Event is from a PDU.Report?

Frank Fock fock at agentpp.com
Wed Aug 2 23:48:20 CEST 2017


Hello Nelson,

You are right, not using Snmp.this at the below quoted code location was an error.
I have corrected this for the next major release.

However, this should not induce a real memory leak, because the ending message context is removed after the timeout anyway. Nevertheless, for some time, more objects exists in memory then required.

As workaround, you can use the user object in the asynchronous request to provide the Snmp instance reference to the async request listener.

Best regards,
Frank


> On 2. Aug 2017, at 12:29, Nelson Silva <nelson.emanuel.silva at gmail.com> wrote:
> 
> Hello,
> 
> I noticed a memory leak when i'm using async requests and i have a lot of
> PDU.Reports.
> 
> 
> From the java doc i found that i need to cancel the request however the
> source from the ResponseEvent is a ReportHandler and i don't have access to
> the Snmp instance.
> 
> // Always cancel async request when response has been received
> *       // otherwise a memory leak is created! Not canceling a request
> *       // immediately can be useful when sending a request to a broadcast
> *       // address.
> *       ((Snmp)event.getSource()).cancel(event.getRequest(), this);
> 
> 
> I was expecting the source to be the Snmp instance.
> 
> On ReportProcessor we have this:
> 
> // return report
> reqListener.onResponse(new ResponseEvent(this,
>    e.getPeerAddress(),
>    reqPDU,
>    pdu,
>    reqUserObject));
> 
> 
> I believe it should be
> 
> reqListener.onResponse(new ResponseEvent(*Snmp.**this*,
> 
>    e.getPeerAddress(),
>    reqPDU,
>    pdu,
>    reqUserObject));
> 
> regards,
> 
> This happens in every versions i have tested, 1.11.2 to 2.5.6
> 
> Nelson Silva
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> https://oosnmp.net/mailman/listinfo/snmp4j



More information about the SNMP4J mailing list