| View previous topic :: View next topic |
| Author |
Message |
Anonimous Guest
|
Posted: Tue Jan 22, 2008 6:17 am Post subject: SNMP Error 22212 [Solved] SNMP library not thread safe |
|
|
Hi,
I'm getting a few SNMP Error 22212 occasionally.
Error No: 22212
Details: SNMP Library not initialized
This is very strange as the SnmpManager object is created and initialized in the beginning of my snmp data retrieval function before attempting any snmpget. The function is called periodically by a worker thread and most of the time, all the snmp operations complete successfully but occasionally, I will find error 22212 half way through the function.
Question: I can perform multiple snmpget from the same snmpManager object, correct?
Here is a simple example of the function in question:
Language: C#
Platform: ASP.NET
string oid = "system.sysName.0"
string systemName;
string systemDesc;
SnmpObject snmpObj = new SnmpObject();
SnmpManager snmpManager = new SnmpManager();
snmpManager.Initialize();
snmpManager.Open( hostName, communityString, snmpPort );
if (snmpManager.LastError != 0) {
break;
}
snmpObj = (SnmpObject)snmpManager.Get( oid );
if (snmpManager.LastError == 0) {
systemName = snmpObj.Value;
}
oid = "system.sysDescr.0";
snmpObj = (SnmpObject)snmpManager.Get( oid );
if (snmpManager.LastError == 0) {
systemDesc = snmpObj.Value;
}
Thanks for your help in advance. |
|
| Back to top |
|
 |
Anonimous Guest
|
Posted: Wed Jan 23, 2008 7:33 am Post subject: |
|
|
Finally work out what the problem is. It turns out the SnmpManager object is not thread safe. Ie if another instance of SnmpManager object is instantiated on a different thread, it seems to knock the library off the first thread and hence the error SNMP Library not initialized.
I've got my code to work by enforcing a single instance of SnmpManager and only a single thread inside the function.
Cheers, Ky |
|
| Back to top |
|
 |
Leon
Joined: 11 Jul 2007 Posts: 405
|
Posted: Wed Jan 23, 2008 9:54 am Post subject: |
|
|
Hello Ky,
Thanks for your post, you are correct, but it is not because our object is not thread safe. We use the windows SnmpLibrary and the problem is in this library. We already have a fix for this issue, but it only solves this problem on Win2003 and higher platforms.
Leon Steijger
ActiveXperts Software |
|
| Back to top |
|
 |
bilenkis
Joined: 13 Jan 2008 Posts: 3
|
Posted: Thu Mar 13, 2008 3:23 am Post subject: |
|
|
Is Microsoft aware of the threading issue with their SNMP library? Maybe they are planning to fix it.
It seems like you might be able to get away with having multiple threads using the same instance of SnmpManager when all the threads want to communicate with the same host. But it will not be possible without a fix to have multiple threads connecting to different hosts.
How do we get your fix for the issue? Will it be in the next version of ActiveSocket? |
|
| Back to top |
|
 |
Leon
Joined: 11 Jul 2007 Posts: 405
|
Posted: Fri Mar 14, 2008 12:55 pm Post subject: |
|
|
Quoted from:
[url]http://msdn2.microsoft.com/en-us/library/aa378004(VS.85).aspx[/url]
The SnmpCleanupEx function performs cleanup when there are no outstanding successful calls to SnmpStartup or SnmpStartupEx within a Windows SNMP (WinSNMP) application. Otherwise, an internal reference count indicating the current number of outstanding successful calls to SnmpStartupEx is decremented.
This function should be used instead of SnmpCleanup if Windows Server 2003 Service Pack 1 (SP1) or later is installed. SnmpCleanupEx enables support for multiple independent software modules that use WinSNMP within the same application. |
|
| Back to top |
|
 |
Kineas
Joined: 10 Jul 2008 Posts: 1
|
Posted: Thu Jul 10, 2008 2:58 pm Post subject: |
|
|
| How is it solved? I have the latest toolkit and it still gives me this error. Heck, if i have too many threads Windows crashes. I am running on Windows Server 2003 SP2 with .Net, and I never managed to crash Windows with my .Net severs. |
|
| Back to top |
|
 |
Leon
Joined: 11 Jul 2007 Posts: 405
|
Posted: Mon Jul 14, 2008 8:52 am Post subject: |
|
|
Hi,
Yes the problem is fixed, but even when it was not, it did not cause crashes.
I have no other complaints about this so far. Is it possible to send a code snippet to see what is wrong ?
Leon |
|
| Back to top |
|
 |
|