[SNMP4J] Possible async/multi-thread race condition

Ronald Madsen Ronald.Madsen at utstar.com
Wed Mar 19 18:33:24 CET 2008


The recent discussion "TableUtils - GetBulk responses - Possible race
condition" prompted me to ask the following:

I am using snmp4j v1.9 with a single Snmp instance and multiple threads,
each doing async get(...) to multiple targets.  At random times, the
response listener is being called with a null response PDU indicating a
timeout - which is not expected.

If I switch to using sync get(...) for each target, no timeouts are
being reported.

More details:

1) Create a single instance of Snmp
2) Create multiple CommunityTargets (5-10) - using different
ipAddresses, same timeout/retry (5 sec, 0 retry)
   Basically this is a set of all known network elements that need to be
polled on private network

Each thread wakes up every 10 minutes to...

3) Create a new PDU request for each target, for some MIB object - like
sysUpTime
4) Create a new ResponseListener (passing number of targets expected to
respond)
5) Issue snmp.get(requestPDU, target, userObject, responseListener) for
each target

   userObject is an Integer representing an index into the target array
enabling
   the response listener to correllate the reponses and know when all
responses
   have been received (or timed-out)

6) The thread does a synchronize/responseListener.wait()
7) When the responseListener determines all responses have been
received, it does
   synchronize/this.notify() un-blocking the calling thread.

99% of the time, this technique works exceptionally well.

Occasionally (2-3 times/day), the responseListener is called with a null
responsePDU for all-but-one of the original targets.  Strange.
Unfortunately it is not predictable, and I have been reluctant to do a
packet capture for 24 hours due to the size of the resulting log files.

My targets are simple SUN boxes that have uptimes in the hundreds of
days - so I don't expect timeouts.

Again, when I switch to using async get(...) I never receive a timeout.

Do you think this might be realated to "TableUtils - GetBulk responses -
Possible race condition"?

Thanks,
Ron



More information about the SNMP4J mailing list