Possible deadlocking between jcifs.smb.Dfs and jcifs.smb.SmbTransport

Xavier Roche <[email protected]>
Newsgroups gmane.network.samba.java
Organization Exalead
Message-ID <[email protected]>
Hi folks!

[ Issue found in jcifs 1.3.17 ]

jcifs.smb.Dfs and jcifs.smb.SmbTransport seems to be deadlocking due to 
Mutex ordering mismatch in the code.

[ Is it safe to use SmbFile in two different threads simultaneously, or 
does it need to be synchronized too ? ]

Typical example: in the following two threads, the locking ordering is 
different

Thread 1:
	jcifs.smb.SmbTransport.getSmbSession(SmbTransport.java:126)
		**** LOCKED(SmbTransport):
			synchronized SmbSession getSmbSession
	jcifs.smb.SmbTransport.getDfsReferrals(SmbTransport.java:701)
	jcifs.smb.Dfs.getReferral(Dfs.java:143)
	jcifs.smb.Dfs.resolve(Dfs.java:191)
		**** LOCKED(Dfs):
			public synchronized DfsReferral
	jcifs.smb.SmbFile.doConnect(SmbFile.java:902)
	jcifs.smb.SmbFile.connect(SmbFile.java:954)
	jcifs.smb.SmbFile.connect0(SmbFile.java:880)
	jcifs.smb.SmbFile.queryPath(SmbFile.java:1335)
	jcifs.smb.SmbFile.exists(SmbFile.java:1417)
	jcifs.smb.SmbFile.isDirectory(SmbFile.java:1490)
	<client code>

Thread 2:
	jcifs.smb.Dfs.insert(Dfs.java:289)
		**** LOCKED(Dfs):
			synchronized void insert
	jcifs.smb.SmbTransport.checkStatus(SmbTransport.java:556)
	jcifs.smb.SmbTransport.send(SmbTransport.java:640)
		**** LOCKED(SmbTransport):
			synchronized (this)
	jcifs.smb.SmbSession.send(SmbSession.java:238)
	jcifs.smb.SmbTree.send(SmbTree.java:119)
	jcifs.smb.SmbFile.send(SmbFile.java:775)
	jcifs.smb.SmbFile.queryPath(SmbFile.java:1363)
	jcifs.smb.SmbFile.exists(SmbFile.java:1417)
	jcifs.smb.SmbFile.isDirectory(SmbFile.java:1490)
	<client code>

I'm available to do more testing if necessary!
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.