[jcifs] Deadlock situation in method SmbTree.treeConnect (jCIFS 1.2.13)

Stig Inge Lea Bjørnsen stig at coretrek.no
Tue Aug 7 12:26:07 GMT 2007


I have encountered a deadlock situation in the method treeConnect of
jcifs.smb.SmbTree in jCIFS 1.2.13. The situation could probably also
arise in 1.2.16 as the diff between SmbTree in 1.2.13 and 1.2.16 is
quite minimal.

The situation is that two threads (named TP-Processor11 and
TP-Processor14) both have entered the method treeConnect. Before
entering treeConnect, the thread TP-Processor11 already had a monitor on
the transport object while TP-Processor14 had no relevant monitors. The
following code snippet from SmbTree shows where the threads are stuck
waiting for each other:

void treeConnect(...

SmbTransport transport = session.transport();

synchronized(transport.setupDiscoLock) { // TP-Processor11 stops here,

                                          // waiting for TP-Processor14
                                          // to release its monitor on
                                          // setupDiscoLock.
synchronized(transport) {  // TP-Processor14 stops here, waiting for
                            // TP-Processor11 to release its monitor on
                            // transport.

Could this deadlock have been avoided by changing treeConnect to
synchronize on transport before it synchronizes on transport.setupDiscoLock?

Below is an excerpt of the thread dump (line numbers are valid for jCIFS

Found one Java-level deadlock:
   waiting to lock monitor 0x6be864e4 (object 0x75b91130, a
   which is held by "TP-Processor14"
   waiting to lock monitor 0x6be864a4 (object 0x75b8e710, a
   which is held by "TP-Processor11"

Java stack information for the threads listed above:
         at jcifs.smb.SmbTree.treeConnect(SmbTree.java:128)
         - waiting to lock <0x75b91130> (a java.lang.Object)
         at jcifs.smb.SmbTree.send(SmbTree.java:64)
         at jcifs.smb.SmbTree.treeDisconnect(SmbTree.java:168)
         - locked <0x75b8e710> (a jcifs.smb.SmbTransport)
         at jcifs.smb.SmbSession.logoff(SmbSession.java:301)
         - locked <0x75b8e710> (a jcifs.smb.SmbTransport)
         at jcifs.smb.SmbTransport.getSmbSession(SmbTransport.java:138)
         - locked <0x75b8e710> (a jcifs.smb.SmbTransport)
         at jcifs.smb.SmbSession.logon(SmbSession.java:167)
         at jcifs.smb.SmbSession.logon(SmbSession.java:162)
        (only application specific classes beyond this point)

         at jcifs.smb.SmbTree.treeConnect(SmbTree.java:130)
         - waiting to lock <0x75b8e710> (a jcifs.smb.SmbTransport)
         - locked <0x75b91130> (a java.lang.Object)
         at jcifs.smb.SmbSession.logon(SmbSession.java:169)
         at jcifs.smb.SmbSession.logon(SmbSession.java:162)
         (only application specific classes beyond this point)

Found 1 deadlock.

Stig Inge Lea Bjørnsen

More information about the jcifs mailing list