lextudio / sharpsnmplib

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

GetBulkRequestMessage crashes with large repetitions #225

Closed lextudio-support closed 4 hours ago

lextudio-support commented 4 hours ago

Hi,

When attempting to run GetBulkRequestMessage with large repetitions that reach the end of the MIB. So if I attempt to pull 40 and there are only 39 in the MIB then the call fails with 2 exceptions thrown

1) System.Net.Sockets.SocketException in System.dll 2) Lextm.SharpSnmpLib.Messaging.TimeoutException in SharpSnmpLib.Full.dll

I believe the GetBulkRequestMessage is not handing the end of the MIB and seeing the failure to respond and a communication error instead.

Original Reported Date: 2015-05-06T08:27:49.437-07:00 Planned For Release:

Original CodePlex ID: 7273

lextudio-support commented 4 hours ago

Copied from CodePlex without authors:

Can you share more info (such as call stack) of the exceptions?

I assume you use {{Messenger.BulkWalk}}. Is that right? "end of MIB" events are only handled in this method, not in the {{GetBulkRequestMessage}} class.

Original Posted Date: 2015-05-06T19:56:57.207-07:00

lextudio-support commented 4 hours ago

Copied from CodePlex without authors:

I am using the GetBulkRequestMessage - I have not experimented with BulkWalk as of yet. I plan to but that's a different process within SNMP.

The messages printed to the immediate window when the error occurs are:

A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll A first chance exception of type 'Lextm.SharpSnmpLib.Messaging.TimeoutException' occurred in SharpSnmpLib.Full.dll

Here is the Exception Detail:

Lextm.SharpSnmpLib.Messaging.TimeoutException was caught HResult=-2146233088 Message=Exception of type 'Lextm.SharpSnmpLib.Messaging.TimeoutException' was thrown. Source=SharpSnmpLib.Full Timeout=5000

StackTrace: at Lextm.SharpSnmpLib.Messaging.SnmpMessageExtension.GetResponse(ISnmpMessage request, Int32 timeout, IPEndPoint receiver, UserRegistry registry, Socket udpSocket) at Lextm.SharpSnmpLib.Messaging.SnmpMessageExtension.GetResponse(ISnmpMessage request, Int32 timeout, IPEndPoint receiver, Socket udpSocket) at Lextm.SharpSnmpLib.Messaging.SnmpMessageExtension.GetResponse(ISnmpMessage request, Int32 timeout, IPEndPoint receiver) at SNMP_Test_Tool.modSNMP.GetBulkSNMP(String[]& Result, String IP_Address, Int32 Port, String Community, String OID, SNMP_Ver SNMPVer, Int32 Timeout, Int32 Repititions) in C:\Users\user\Documents\Visual Studio 2013\Projects\SNMP Tool\modSNMP.vb:line 82

Here is my code:

Assume SNMPVer = 2, Community = public (or what ever your using for v2), Repetitions = 70, and OID = .1.3.6.1.4.1.850.100.1.1 (but you'll need to use an OID that woks on your system.

        Dim SNMPmessage As New GetBulkRequestMessage(0, SNMPVer, _
                                                     New OctetString(Community), _
                                                     0, Repititions, _
                                                     New List(Of Variable)() From {New Variable(New ObjectIdentifier(OID))})

        Dim SNMPresponse As ISnmpMessage

        Try
            SNMPresponse = SNMPmessage.GetResponse(Timeout, New IPEndPoint(IPAddress.Parse(IP_Address), Port))
        Catch ex As Exception
            ReDim Result(1)
            Result(0) = ex.Message
            Call Debug.Print(Result(0))
            Return False
        End Try

Original Posted Date: 2015-05-07T07:02:30.407-07:00

lextudio-support commented 4 hours ago

Copied from CodePlex without authors:

Here is a wireshark capture of the network traffic sent across.

Original Posted Date: 2015-05-07T07:30:28.747-07:00

lextudio-support commented 4 hours ago

Copied from CodePlex without authors:

And here's one using iReasoning. Notice the addition of the time-out message at line 122 that is not there with iReasoning...

Original Posted Date: 2015-05-07T07:36:29.34-07:00

lextudio-support commented 4 hours ago

Copied from CodePlex without authors:

Hi lextm - Just wanted to check back and see if you have been able to look into this?

Original Posted Date: 2015-05-20T12:17:15.487-07:00

lextudio-support commented 4 hours ago

Copied from CodePlex without authors:

Thanks for sharing the captures. From them I can only tell this is a common timeout issue.

21    *REF*    manager_ip    agent_ip    SNMP    87    getBulkRequest 
121  6.097113000    agent_ip    manager_ip   SNMP    108    get-response

For example, from both captures you can see typical conversation like above, where the agent takes more than 6 seconds to reply. That's ok as GET BULK often passes lots of data.

However, when you make the call, the timeout value was too small (5000 in exception message, which means 5 seconds).

Can you check what is the timeout setting you use for iReasoning? I think by enlarging the timeout value in your code, #SNMP should work just as fine as iReasoning.

Original Posted Date: 2015-05-22T06:19:03.773-07:00

lextudio-support commented 4 hours ago

Copied from CodePlex without authors:

Hi Lex,

iReasoning was at 10 seconds... The longer timeout seems to have fixed it but I had to make it 15-20. Not a big deal..

But it raises a new issue - I'm expecting say 100 items returned but it's only 56. How can I read the number of actual items returned so I can adjust my expected # down without doing a loop to count the items?

Original Posted Date: 2015-05-22T07:38:21.99-07:00

lextudio-support commented 4 hours ago

Copied from CodePlex without authors:

Never mind Lex, I found the Count property (not sure how I missed it before) :-/

SNMPresponse.Pdu.Variables.Count

Original Posted Date: 2015-05-22T08:55:19.053-07:00

lextudio-support commented 4 hours ago

Original Closed Date: 2015-05-23T02:31:51.523-07:00