lextudio / sharpsnmplib

Sharp SNMP Library- Open Source SNMP for .NET
https://sharpsnmp.com
MIT License
356 stars 152 forks source link

Response message received doesn't match with the request sent. #295

Closed lextudio-support closed 2 hours ago

lextudio-support commented 2 hours ago

This issue was observed when we used SnmpMessageExcetnsion.BeginGetResponse method to send tens or hundreds of requests per second. To avoid the creation and destroy of socket instances for each request/response, we hold a socket instance in our module, and passed that socket instance in each time we call BeginGetResponse method. Then we found some responses didn't match with the original requests(the request ID in the response doesn't match with that of the request).

This issue only happens when one single socket instance is used in sending large number of request simultaneously.

Analysis on this issue In the BeginGetResponse method, it starts receiving response once the request has been sent out. Then, it returns the next received response message as the RESPONSE for the request sent before. But in a high-stress scenario, there may be multiple outstanding requests, and the response message may be received in any order, so the next response message received may not be the response for the request just sent.

Possible solution To solve this issue, a request-response matching mechanism is needed. It should keep track of all outstanding requests, and match the received response with corresponding outstanding request, and then complete the conversion by returning the correct response message.

Thanks

Original Reported Date: 2013-01-06T22:30:22.5-08:00 Planned For Release: Original CodePlex ID: 7247

lextudio-support commented 2 hours ago

Copied from CodePlex without authors:

This should be treated as a large feature request "how to reuse Socket object(s)", which is not supported by #SNMP right now.

A long time ago #SNMP used to use a single Socket object to handle SNMP messages (as you did) to minimize resource consumption, but it turned out to be too difficult to manage as socket exceptions and so on can corrupt a Socket object. So later every call uses a new Socket object (though the socket reuse interfaces were not removed)

Message ID matching might help, but without a general and stable mechanism to reuse the Socket, more issues might arise than expected.

I don't have a complex enough environment to test, so if you are interested in this topic and willing to contribute, you might fork #SNMP at GitHub (https://github.com/lextm/sharpsnmplib) and attempt to implement your ideas. I am more than happy to accept your pull request when you finish hacking.

Regards,

Lex

Original Posted Date: 2013-01-09T05:44:33.07-08:00

lextudio-support commented 2 hours ago

Original Closed Date: 2013-06-09T00:49:12.78-07:00