[jcifs] Thread deadlock

Michael B Allen ioplex at gmail.com
Fri Oct 23 12:53:50 MDT 2009


Hi Tony,

That is a known deadlock. If you get enough threads going at the same
time you can get a thread that is trying to disconnect an SMB
connection locked with another thread that is trying to connect. But I
believe this requires a LOT of threads like someone might use with
some kind of "torture test". I don't recall if anyone has reported
seeing this in a practical application in production.

The problem and the fix has been discussed at length on this mailing
list in the past. The fix is to not use Java's builtin thread
synchronization and instead create a custom condition variable class
(or maybe something based on Java's ReentrantLock) that it could be
unlocked deep in the call stack where the thread is waiting for an
event.

The problem is that the builtin synchronized(object) {} block style
locking cannot be un-synchronized deep in the call stack. So we need a
lock class that can be locked and unlocked explicitly. Then we can
unlock it deep in the call stack thereby allowing us to use a single
lock for each transport (or maybe even one single lock throughout the
library if there's no blocking while it's held). If you only have one
lock you can't deadlock.

Unfortunately I just don't have "Free" time anymore to spend on this
sort of thing. So this is something that will have to wait for JCIFS
2.x which is on hold indefinitely until I can find time and money.

Mike

On Fri, Oct 23, 2009 at 12:06 PM, Tony Thompson
<Tony.Thompson at stone-ware.com> wrote:
> I am using jCIFS 1.2.19 (I know, a little old but I have issues with 1.3
> that I haven't had time to work out).  I have two threads that are
> deadlocked in jCIFS code.  Can anyone give me a hint why these threads are
> hung?
>
> "RMI TCP Connection(10131)-10.4.8.50" - Thread t at 6308
>    java.lang.Thread.State: BLOCKED on jcifs.smb.SmbTransport at 6005a6c5 owned
> by: RMI TCP Connection(10121)-10.4.8.50
> at jcifs.smb.SmbTree.treeConnect(SmbTree.java:128)
> - locked java.lang.Object at 3ff2cf76
> at jcifs.smb.SmbTree.send(SmbTree.java:64)
> at jcifs.smb.SmbFile.send(SmbFile.java:718)
> at jcifs.smb.SmbFile.queryPath(SmbFile.java:1297)
> at jcifs.smb.SmbFile.exists(SmbFile.java:1351)
> ....
>
> "RMI TCP Connection(10121)-10.4.8.50" - Thread t at 6274
>    java.lang.Thread.State: BLOCKED on java.lang.Object at 3ff2cf76 owned by:
> RMI TCP Connection(10131)-10.4.8.50
> at jcifs.smb.SmbTree.treeConnect(SmbTree.java:127)
> at jcifs.smb.SmbTree.send(SmbTree.java:64)
> at jcifs.smb.SmbTree.treeDisconnect(SmbTree.java:168)
> - locked jcifs.smb.SmbTransport at 6005a6c5
> at jcifs.smb.SmbSession.logoff(SmbSession.java:312)
> - locked jcifs.smb.SmbTransport at 6005a6c5
> at jcifs.smb.SmbTransport.getSmbSession(SmbTransport.java:141)
> - locked jcifs.smb.SmbTransport at 6005a6c5
> at jcifs.smb.SmbFile.doConnect(SmbFile.java:834)
> at jcifs.smb.SmbFile.connect(SmbFile.java:890)
> at jcifs.smb.SmbFile.connect0(SmbFile.java:816)
> at jcifs.smb.SmbFile.queryPath(SmbFile.java:1269)
> at jcifs.smb.SmbFile.exists(SmbFile.java:1351)
> ....
>
> Thanks
> Tony
>
> This message (and any associated files) is intended only for the
> use of the individual or entity to which it is addressed and may
> contain information that is confidential, subject to copyright or
> constitutes a trade secret. If you are not the intended recipient
> you are hereby notified that any dissemination, copying or
> distribution of this message, or files associated with this message,
> is strictly prohibited. If you have received this message in error,
> please notify us immediately by replying to the message and deleting
> it from your computer. Messages sent to and from Stoneware, Inc.
> may be monitored.
>
>



-- 
Michael B Allen
Java Active Directory Integration
http://www.ioplex.com/


More information about the jCIFS mailing list