You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@clerezza.apache.org by "Reto Bachmann-Gmür (JIRA)" <ji...@apache.org> on 2011/06/15 10:16:47 UTC

[jira] [Commented] (CLEREZZA-557) Potential Deadlock in UnionLock

    [ https://issues.apache.org/jira/browse/CLEREZZA-557?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13049676#comment-13049676 ] 

Reto Bachmann-Gmür commented on CLEREZZA-557:
---------------------------------------------

the proposed patch looks good, I guess this solves the issue.

> Potential Deadlock in UnionLock
> -------------------------------
>
>                 Key: CLEREZZA-557
>                 URL: https://issues.apache.org/jira/browse/CLEREZZA-557
>             Project: Clerezza
>          Issue Type: Bug
>            Reporter: Tsuyoshi Ito
>            Priority: Critical
>
> 2 Threads:
> Thread A and Thread B
> Thread A tries to set a writelock on UnionMGraph consisting of Graphs AG, BG, CG and DG (AG is write locked, BG, CG, DG should be readlocked). BG and CG was successfully readlocked by thread A but in the mean while Thread B tries to set a writelock on a UnionMGraph constisting of DG, AG and EG. Thread B was able to writelock DG but has to wait for the readlock on AG (is writelocked by thread A). thread A has to wait for the readlock on the graph DG => Deadlock
> I suggest to refactor lock in UnionLock as follows:
> @Override
> 		public void lock() {
> 			while(!tryLock()) {
> 				try {
> 					Thread.sleep(10);
> 				} catch (InterruptedException ex) {
> 					
> 				}
> 			}
> 		}
> instead of:
> @Override
> 		public void lock() {
> 			for(Lock lock : locks) {
> 				lock.lock();
> 				}
> 			}
> 		}
> I was able to reproduce it:
> ----------------------------------------------------
> http://tpf.localhost/content.graph
> Read-Lock count:    0
> Write-Locked:       YES
> Has queued threads: YES
> Thread holding write-lock: 
> java.lang.Throwable
> 	at java.lang.Thread.getStackTrace(Thread.java:1426)
> 	at org.apache.clerezza.rdf.core.access.debug.WriteLockDebug.lock(WriteLockDebug.java:55)
> 	at org.apache.clerezza.rdf.utils.UnionMGraph$UnionLock.lock(UnionMGraph.java:237)
> 	at org.clerezza.cms.utils.LockUtils.runLocked(LockUtils.java:66)
> 	at org.clerezza.app.conceptmanager.core.ConceptManager.getConcept(ConceptManager.java:169)
> 	at org.clerezza.app.conceptmanager.core.ConceptManager.storeConcept(ConceptManager.java:160)
> ......
> Queue length:       1
> Queued threads: 
> 42java.lang.Throwable
> 	at sun.misc.Unsafe.park(Native Method)
> 	at java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
> 	at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:747)
> 	at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireShared(AbstractQueuedSynchronizer.java:877)
> 	at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireShared(AbstractQueuedSynchronizer.java:1197)
> 	at java.util.concurrent.locks.ReentrantReadWriteLock$ReadLock.lock(ReentrantReadWriteLock.java:594)
> 	at org.apache.clerezza.rdf.core.access.debug.ReadLockDebug.lock(ReadLockDebug.java:44)
> 	at org.apache.clerezza.rdf.utils.UnionMGraph$UnionLock.lock(UnionMGraph.java:237)
> ----------------------------------------------------
> http://tpf.localhost/feed.graph
> Read-Lock count:    0
> Write-Locked:       YES
> Has queued threads: YES
> Thread holding write-lock: 
> java.lang.Throwable
> 	at java.lang.Thread.getStackTrace(Thread.java:1426)
> 	at org.apache.clerezza.rdf.core.access.debug.WriteLockDebug.lock(WriteLockDebug.java:55)
> 	at org.apache.clerezza.rdf.core.access.LockableMGraphWrapper.remove(LockableMGraphWrapper.java:176)
> 	at org.apache.clerezza.rdf.utils.GraphNode.deleteProperties(GraphNode.java:536)
> ....
> Queue length:       1
> Queued threads: 
> 45java.lang.Throwable
> 	at sun.misc.Unsafe.park(Native Method)
> 	at java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
> 	at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:747)
> 	at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireShared(AbstractQueuedSynchronizer.java:877)
> 	at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireShared(AbstractQueuedSynchronizer.java:1197)
> 	at java.util.concurrent.locks.ReentrantReadWriteLock$ReadLock.lock(ReentrantReadWriteLock.java:594)
> 	at org.apache.clerezza.rdf.core.access.debug.ReadLockDebug.lock(ReadLockDebug.java:44)
> 	at org.apache.clerezza.rdf.utils.UnionMGraph$UnionLock.lock(UnionMGraph.java:237)
> 	at org.apache.clerezza.rdf.utils.UnionMGraph$UnionLock.lock(UnionMGraph.java:237)
> 	at org.clerezza.cms.utils.LockUtils.runLocked(LockUtils.java:66)
> 	at org.clerezza.app.conceptmanager.core.ConceptManager.getConcept(ConceptManager.java:169)
> 	at org.clerezza.app.conceptmanager.core.ConceptManager.storeConcept(ConceptManager.java:160)

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira