[jcifs] deadlock during scheduled logoffs

Michael B Allen mba2000 at ioplex.com
Tue Nov 14 22:39:00 GMT 2006


The setupDiscoLock was specifcally added to resolve deadlocks caused by
the transport logging sessions off at the same time a thread was trying
to logon. The key is to ALWAYS lock the setupDiscoLock FIRST and then
go ahead and do whatever else. So you need to figure out how someone
locked something other than the setupDiscoLock and then change the code
so that the setupDiscoLock get's had first. This might require changing
some code like:

synchronized void metho() {
	...
}

to

void metho() {
	synchronized(setupDiscoLock) {
		synchronized(this) {
			...
		}
	}
}

I wouldn't try to reverse the order of things as that will probably just
expose a concurrency flaw some other way.

Note that the PROPER way to fix all of this is to add a ConditionVariable
class that can be explicitly locked and then unlocked deep within the
call stack. The 'synchronized' mechanism is too simple. It needs to be
replaced with explicit locking [1]. Unfortunately I didn't realize that
when I did the last Transport rewrite.

Mike

[1] If someone feels compelled to do this work, please do not use the
bloated java.util.concurrency package. Just write one small simple
class.

On Tue, 14 Nov 2006 15:30:00 -0600
"Christensen, Scott M" <SCHRIST1 at amfam.com> wrote:

> Hi,
> 
>  
> 
> We are having a deadlock issue that has to do with the setupDiscoLock in
> the transport object.  This is happening in 1.2.9.  I have reviewed the
> code in 1.2.10 and this issue will still occur. What appears to be
> happening is that at a scheduled time (every 35 seconds by default),
> during a getSmbSession() in SmbTransport, SmbTransport attempts to do
> some cleanup of existing but expired sessions by calling their logoff
> method which locks the SmbTransport object.  It eventually calls the
> treeConnect method in SmbTree which attempts to first lock the
> setupDiscoLock and then the transport object.  However if another thread
> calls the logon method the thread eventually gets to the treeConnect
> method and locks the setupDiscoLock.  It is then waiting to lock the
> transport object while the first thread has the transport and is waiting
> to lock the setupDiscoLock.
> 
>  
> 
> I guess I'm wondering what is the best way to fix this issue.  I've
> thought of a couple of ways and would like to get the ramifications of
> each.
> 
>  
> 
> 1.	Reverse the locks in the treeConnect method of SmbTree.  This
> would require that the transport be locked before locking the
> setupDiscoLock.
> 2.	Synchronize the logoff call in the "cleanup block" of
> SmbTransport.getSmbSession on the transport.
> 3.	Other better ideas?
> 
>  
> 
> I admit that the locking mechanisms employed are slightly beyond my
> total comprehension, so if I'm way off base, let me know.  I would just
> like a way to find a resolution to this issue.  Below is a thread dump
> of the deadlock we are seeing.
> 
>  
> 
> Thanks,
> 
> Scott
> 
>  
> 
> Found one Java-level deadlock:
> 
> =============================
> 
> "Servlet.Engine.Transports : 49":
> 
>   waiting to lock monitor 002ae7c8 (object 45ceabc0, a
> java.lang.Object),
> 
>   which is held by "Servlet.Engine.Transports : 67"
> 
> "Servlet.Engine.Transports : 67":
> 
>   waiting to lock monitor 002ae748 (object 45cd7180, a
> jcifs.smb.SmbTransport),
> 
>   which is held by "Servlet.Engine.Transports : 49"
> 
>  
> 
> Java stack information for the threads listed above:
> 
> ===================================================
> 
> "Servlet.Engine.Transports : 49":
> 
>       at jcifs.smb.SmbTree.treeConnect(SmbTree.java:130)
> 
>       - waiting to lock <45ceabc0> (a java.lang.Object)
> 
>       at jcifs.smb.SmbTree.send(SmbTree.java:57)
> 
>       at jcifs.smb.SmbTree.treeDisconnect(SmbTree.java:179)
> 
>       - locked <45cd7180> (a jcifs.smb.SmbTransport)
> 
>       at jcifs.smb.SmbSession.logoff(SmbSession.java:311)
> 
>       - locked <45cd7180> (a jcifs.smb.SmbTransport)
> 
>       at jcifs.smb.SmbTransport.getSmbSession(SmbTransport.java:138)
> 
>       - locked <45cd7180> (a jcifs.smb.SmbTransport)
> 
>       at jcifs.smb.SmbSession.logon(SmbSession.java:177)
> 
>       at jcifs.smb.SmbSession.logon(SmbSession.java:172)
> 
>       at
> com.myapp.authenticator.DomainController.logon(DomainController.java:70)
> 
>       at
> com.myapp.authenticator.delegate.NtlmAuthenticationDelegate.processLogin
> (NtlmAuthenticationDelegate.java:150)
> 
>       at com.myapp.Authenticator.processLogin(Authenticator.java:210)
> 
>       at
> org.securityfilter.filter.SecurityFilter.doFilter(SecurityFilter.java:13
> 1)
> 
>       at com.myapp.SecurityFilter.doFilter(SecurityFilter.java:172)
> 
>       at
> com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInst
> anceWrapper.java:132)
> 
>       at
> com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterCh
> ain.java:71)
> 
>       at
> com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispa
> tch(WebAppRequestDispatcher.java:1009)
> 
>       - locked <529511b0> (a
> com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher)
> 
>       at
> com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRe
> questDispatcher.java:529)
> 
>       - locked <529511b0> (a
> com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher)
> 
>       at
> com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppReq
> uestDispatcher.java:208)
> 
>       - locked <529511b0> (a
> com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher)
> 
>       at
> com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:1
> 34)
> 
>       at
> com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInv
> oker.java:321)
> 
>       at
> com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocati
> on(CachedInvocation.java:71)
> 
>       at
> com.ibm.ws.webcontainer.cache.invocation.CacheableInvocationContext.invo
> ke(CacheableInvocationContext.java:120)
> 
>       at
> com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(Servle
> tRequestProcessor.java:250)
> 
>       at
> com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSELis
> tener.java:334)
> 
>       at
> com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection
> .java:56)
> 
>       at
> com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:
> 652)
> 
>       at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:458)
> 
>       at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:936)
> 
> "Servlet.Engine.Transports : 67":
> 
>       at jcifs.smb.SmbTree.treeConnect(SmbTree.java:132)
> 
>       - waiting to lock <45cd7180> (a jcifs.smb.SmbTransport)
> 
>       - locked <45ceabc0> (a java.lang.Object)
> 
>       at jcifs.smb.SmbSession.logon(SmbSession.java:179)
> 
>       at jcifs.smb.SmbSession.logon(SmbSession.java:172)
> 
>       at
> com.myapp.authenticator.DomainController.logon(DomainController.java:70)
> 
>       at
> com.myapp.authenticator.delegate.NtlmAuthenticationDelegate.processLogin
> (NtlmAuthenticationDelegate.java:150)
> 
>       at com.myapp.Authenticator.processLogin(Authenticator.java:210)
> 
>       at
> org.securityfilter.filter.SecurityFilter.doFilter(SecurityFilter.java:13
> 1)
> 
>       at com.myapp.SecurityFilter.doFilter(SecurityFilter.java:172)
> 
>       at
> com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInst
> anceWrapper.java:132)
> 
>       at
> com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterCh
> ain.java:71)
> 
>       at
> com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispa
> tch(WebAppRequestDispatcher.java:1009)
> 
>       - locked <5b665c28> (a
> com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher)
> 
>       at
> com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRe
> questDispatcher.java:529)
> 
>       - locked <5b665c28> (a
> com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher)
> 
>       at
> com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppReq
> uestDispatcher.java:208)
> 
>       - locked <5b665c28> (a
> com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher)
> 
>       at
> com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:1
> 34)
> 
>       at
> com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInv
> oker.java:321)
> 
>       at
> com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocati
> on(CachedInvocation.java:71)
> 
>       at
> com.ibm.ws.webcontainer.cache.invocation.CacheableInvocationContext.invo
> ke(CacheableInvocationContext.java:120)
> 
>       at
> com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(Servle
> tRequestProcessor.java:250)
> 
>       at
> com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSELis
> tener.java:334)
> 
>       at
> com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection
> .java:56)
> 
>       at
> com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:
> 652)
> 
>       at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:458)
> 
>       at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:936)
> 
>  
> 
> Found 1 deadlock.
> 
>  
> 
> 


-- 
Michael B Allen
PHP Active Directory SSO
http://www.ioplex.com/


More information about the jcifs mailing list