[AGENT++] Crash in multi-threaded SNMP++ use (usm_v3.cpp:1262)

John McCaskey jmccaskey at gmail.com
Mon Mar 13 21:24:47 CET 2006


Hi Jochen,

First thank you very much for the quick and insightful response, see my
comments and additional questions inline :)

On 3/13/06, Jochen Katz <katz at agentpp.com> wrote:
>
> Hi John,
>
> > 2) In each individual thread (the application creates about 80 threads
> > dedicated to polling individual SNMP enabled devices) I create a new
> Snmp
> > object and intialize it with the right settings, as part of this if the
> > device to be polled is SNMP v3 then I do:
> > USM *usm = v3_MP->get_usm();
> > usm->add_usm_user(device.snmp_configuration.version3.snmp_username,
> >                 authProtocol, privProtocol,
> >                 device.snmp_configuration.version3.snmp_auth_password,
> >                 device.snmp_configuration.version3.snmp_priv_password);
>
> > It's my understanding this should be thread safe
>
> yes it should be thread safe, but it is not. As it isn't a simple
> lock/unlock issue you have to use the following temporary workaround
> until I can provide a fixed version.
> Add Snmp::v3Lock.lock(); and Snmp::v3Lock.unlock(); around the call to
> add_usm_user().


Ok, that makes sense as a work around.  The issue I have now is related to
my other email this morning about the unresolved externals which is popping
up again when trying to use the Snmp::v3Lock object.  That's perhaps a
problem with my build environment through and I'll continue to work on that.

> res->engineID           = user_table_entry->usmUserEngineID;
> >
> > The problem seems to be that user_table_entry is NULL.  Right above the
> line
> > that crashses there is a check that res is not null, but no check on
> > user_table_entry.
>
> The check for user_table_entry is left out, because the code above
> should make sure that it is set. Is it possible that two of your threads
> try to add the same user at the same time? Then the second thread could
> delete the newly added entry of the first thread.


Makes sense...

Just an additional hint: Adding user names takes some time (ok, not that
> much on current hardware), so it would be better to add each user once
> and only change it if needed.


What I'm doing is polling a large number of individual devices every 5
minutes, some of the devices may use the same username, but have different
passwords or other authentication settings.  So what I'm doing right now is
always adding the user when one of my worker threads starts on a new device.
Is there a potential thread safety issue if in thread 1 I add a user say
'userWithAuth', setup an Snmp object utilizing the UTarget, then before
finishing use of that Snmp session a context switch occurs to thread 2 which
then adds a new user with the same name, but a different password?

Regards,
>   Jochen
>
> _______________________________________________
> AGENTPP mailing list
> AGENTPP at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/agentpp
>



More information about the AGENTPP mailing list