Login  
Search All Forums
Dart Home | PowerSNMP for .NET | Custom Development Reply | PowerSNMP for .NET Topics | Forums   
AuthorForum: PowerSNMP for .NET
Topic: NullReferenceException when sending multiple InformMessages
andershavn

From: Denmark
Posts: 16
Member Since: 01/07/14
posted February 19, 2014 6:44 AM

Hi,

I get a NullReferenceException when trying to send multiple InformMessages:

...
for (int i = 0; i < 500; i++)
   {
    var informMessage = new InformMessage();
    informMessage.Variables.Add(new Variable(_agent.Mib[NodeName.sysDescr.ToString()], "Test descrip"));
    _agent.Start(OnSendRequestMessage, informMessage);
   }
...

private static void OnSendRequestMessage(SnmpSocket snmpSocket, object requestMessageObject)
  {
    var requestMessage = (RequestMessage)requestMessageObject;
    requestMessage.Version = SnmpVersion.Three;
    requestMessage.Security.User = _agent.Security.AuthoritativeEngine.Users["omnisoft"];
    var responseMessage = snmpSocket.GetResponse(requestMessage, new IPEndPoint(LocalIPAddress(), 10161));
  }

The exception occurs in snmpSocket.GetResponse. Shouldn't it be possible to call "_agent.Start(OnSendRequestMessage, informMessage)" multiple times?

I'm sending to another agent that create a response and sends it back.
It works fine when just sending one InformMessage or when sending them with a delay betweeen them.

Best Regards,
Anders Havn
Nick B (Admin)

From: Utica, NY USA
Posts: 584
Member Since: 05/25/10

Extra Support Options
Custom Application Development

posted February 19, 2014 12:38 PM

Hello,

Can you send in the stack trace and full exception text, along with any inner exceptions? I'd like to check where the exception is coming from.

I tested this with our included Agent sample; I modified the SendInformMessage method in AgentModel.cs and surrounded the Start method it contains with a 500-count for loop, started two instances of the Agent sample (on two different machines on the same network), added the 2nd agent to the first agent's Manager's list, configured it for SNMPv3 with Auth and Priv, sent the 500 informs (from the right-click context menu) and successfully received the responses without any NullReferenceException. Are you able to reproduce your issue with the included sample with the modification I outlined above?

Are you intending on 500 concurrent threads all sending the inform to a single agent and receiving the response (nearly) simultaneously? Depending upon your computer and network performance, there could be some issue on the receiving agent successfully receiving and responding to all of the requests (such as dropped data, since the receiving buffers could be saturated), as the requests are all sent to the same port.
andershavn

From: Denmark
Posts: 16
Member Since: 01/07/14
posted February 25, 2014 4:03 AM

Hi again,

The exception doesn't happen everytime I run the code, "only" about 50 % of the time. If the crash happens it happens right away.

The inner exception is null but this is the call stack:
> mscorlib.dll!System.Collections.Generic.Dictionary<System.Net.IPEndPoint,Dart.Snmp.AuthoritativeEngine>.Insert(System.Net.IPEndPoint key, Dart.Snmp.AuthoritativeEngine value, bool add) + 0x8a bytes
  mscorlib.dll!System.Collections.Generic.Dictionary<System.__Canon,System.__Canon>.Add(System.__Canon key, System.__Canon value) + 0xb bytes
  Dart.Snmp.dll!Dart.Snmp.SnmpSocket.Receive(Dart.Snmp.RequestMessage request, System.Net.IPEndPoint remoteEP) + 0x1d8 bytes
  Dart.Snmp.dll!Dart.Snmp.SnmpSocket.GetResponse(Dart.Snmp.RequestMessage request, System.Net.IPEndPoint remoteEP, int retries) + 0x66 bytes
  Dart.Snmp.dll!Dart.Snmp.SnmpSocket.GetResponse(Dart.Snmp.RequestMessage request, System.Net.IPEndPoint remoteEP) + 0x30 bytes
  TestSubAgent.exe!TestSubAgent.Program.OnSendRequestMessage(Dart.Snmp.SnmpSocket snmpSocket, object requestMessageObject) Line 66 + 0x43 bytes C#
  Dart.Snmp.dll!Dart.Snmp.SnmpBase.14(object ) + 0xd9 bytes
  mscorlib.dll!System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(object state) + 0x3e bytes
  mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0xa7 bytes
  mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x16 bytes
  mscorlib.dll!System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() + 0x60 bytes
  mscorlib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch() + 0x149 bytes
  mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() + 0x5 bytes
  [Native to Managed Transition]


It looks like it is a problem with a dictionary that is being accessed while also written to. My guess is that it has something to do with the SNMPv3 discovery message.

Thanks.

Best Regards,
Anders Havn
Reply | PowerSNMP for .NET Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX