[snmp] deadlock when destroying a context

Josh Bers jbers at bbn.com
Tue Jan 23 13:48:25 GMT 2007


When using a context to send a trap pdu my code runs into a thread deadlock
in the stack. One thread is destroying the context while the other is
transmitting.  The stack should protect against this kind of deadlock
 
1 thread: Transmitter (locked) is in transmit and is trying to lock the
Context to remove a Pdu
2 thread: Context (locked) is in destroy and is trying to lock the
Transmitter to free it.
 
AbstractSnmpContext.destroy() :
 
        // If run() has been started, then it will destroy the
        // transmitter threads when it finishes. Otherwise they must be
        // destroyed here.
        if (me == null)
        {
            freeTransmitters();
        }

 
 
meanwhile removePdu method is being called from the Pdu.transmit()...
 
Looks like some better coordination scheme (finer grained sychronization) is
needed here...
 
See the thread dump below 
 
    [junit] Full thread dump Java HotSpot(TM) Client VM (1.4.2_12-b03 mixed
mode):
...
    [junit] Found one Java-level deadlock:
    [junit] =============================
    [junit] "localhost_1162_0.0.0.0_v0_Trans0":
    [junit]   waiting to lock monitor 0x08092c0c (object 0xab3f7cf0, a
uk.co.westhawk.snmp.stack.SnmpContext)
,
    [junit]   which is held by "main"
    [junit] "main":
    [junit]   waiting to lock monitor 0x08092b64 (object 0xab405f28, a
uk.co.westhawk.snmp.stack.Transmitter)
,
    [junit]   which is held by "localhost_1162_0.0.0.0_v0_Trans0"
 
    [junit] Java stack information for the threads listed above:
    [junit] ===================================================
    [junit] "localhost_1162_0.0.0.0_v0_Trans0":
    [junit]     at
uk.co.westhawk.snmp.stack.AbstractSnmpContext.removePdu(AbstractSnmpContext.
java:674)
    [junit]     - waiting to lock <0xab3f7cf0> (a
uk.co.westhawk.snmp.stack.SnmpContext)
    [junit]     at uk.co.westhawk.snmp.stack.Pdu.transmit(Pdu.java:699)
    [junit]     at
uk.co.westhawk.snmp.stack.TrapPduv1.transmit(TrapPduv1.java:236)
    [junit]     at
uk.co.westhawk.snmp.stack.Transmitter.run(Transmitter.java:80)
    [junit]     - locked <0xab405f28> (a
uk.co.westhawk.snmp.stack.Transmitter)
    [junit]     at java.lang.Thread.run(Thread.java:534)
    [junit] "main":
    [junit]     at
uk.co.westhawk.snmp.stack.Transmitter.stand(Transmitter.java:144)
    [junit]     - waiting to lock <0xab405f28> (a
uk.co.westhawk.snmp.stack.Transmitter)
    [junit]     at
uk.co.westhawk.snmp.stack.Transmitter.destroy(Transmitter.java:161)
    [junit]     at
uk.co.westhawk.snmp.stack.AbstractSnmpContext.freeTransmitters(AbstractSnmpC
ontext.java:93
4)
    [junit]     at
uk.co.westhawk.snmp.stack.AbstractSnmpContext.destroy(AbstractSnmpContext.ja
va:470)
    [junit]     - locked <0xab3f7cf0> (a
uk.co.westhawk.snmp.stack.SnmpContext)

 


More information about the snmp mailing list