History | Log In     View a printable version of the current page. Get help!  
Issue Details [XML]

Key: ELMO-19
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Peter Mika
Reporter: Peter Mika
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Elmo

Deadlock when separate threads are manipulating the same ElmoRepository

Created: 02/Sep/06 06:24 PM   Updated: 02/Sep/06 08:06 PM
Component/s: Object Model
Affects Version/s: 0.2
Fix Version/s: 0.3


 Description   
In Elmo, we have the following core classes:

ElmoRepository is a thin wrapper of SesameRepository. It exposes the same methods as SesameRepository plus adds two things: caching for repository objects and an own listener mechanism (ElmoRepositoryEvent and ElmoRepositoryListener).

ElmoSession is a bit more extensive wrapper around an ElmoRepository that allows to manipulate data at the ontology level. (This is the main class of Elmo basically.)

The deadlock occurs when

-- one thread is reading the repostory through a JavaBean
-- another thread is writing it through ElmoRepository

The tricky thing is that while ElmoRepository and SesameRepository can be properly synchronized on their own, there can still be a race between them when

-- the first thread is in the getCacheMap method of ElmoSession trying to read the repository
-- the second thread has modified the repository and trying to notify the ElmoSession

In this case the first thread is holding the lock to the ElmoSession and the second is holding the lock for the Repository. They are waiting for the each other and the result is a deadlock.

I found and fixed this bug myself but thought it is interesting enough to document.


 All   Comments   Change History      Sort Order:
Change by Peter Mika [02/Sep/06 06:27 PM]
Field Original Value New Value
Description In Elmo, we have the following core classes:

ElmoRepository is a thin wrapper of SesameRepository. It exposes the same methods as SesameRepository plus adds two things: caching for repository objects and an own listener mechanism (ElmoRepositoryEvent and ElmoRepositoryListener).

ElmoSession is a bit more extensive wrapper around an ElmoRepository that allows to manipulate data at the ontology level. (This is the main class of Elmo basically.)

The deadlock occurs when

-- one thread is reading the repostory through a JavaBean
-- another thread is writing it through ElmoRepository

The tricky thing is that while ElmoRepository and SesameRepository can be properly synchronized on their own, there can still be a race between them when

-- the first thread is in the getCacheMap method of ElmoSession trying to read the repository
-- the second thread has modified the repository and trying to notify the ElmoSession

In this case the first thread is holding the lock to the ElmoSession and the second is holding the lock for the Repository. They are waiting for the each other and the result is a deadlock.







I found and fixed this bug myself but thought it is interesting enough to document.
In Elmo, we have the following core classes:

ElmoRepository is a thin wrapper of SesameRepository. It exposes the same methods as SesameRepository plus adds two things: caching for repository objects and an own listener mechanism (ElmoRepositoryEvent and ElmoRepositoryListener).

ElmoSession is a bit more extensive wrapper around an ElmoRepository that allows to manipulate data at the ontology level. (This is the main class of Elmo basically.)

The deadlock occurs when

-- one thread is reading the repostory through a JavaBean
-- another thread is writing it through ElmoRepository

The tricky thing is that while ElmoRepository and SesameRepository can be properly synchronized on their own, there can still be a race between them when

-- the first thread is in the getCacheMap method of ElmoSession trying to read the repository
-- the second thread has modified the repository and trying to notify the ElmoSession

In this case the first thread is holding the lock to the ElmoSession and the second is holding the lock for the Repository. They are waiting for the each other and the result is a deadlock.

I found and fixed this bug myself but thought it is interesting enough to document.

Change by Peter Mika [02/Sep/06 06:28 PM]
Field Original Value New Value
Component/s Object Model [ 10080 ]

Comment by Peter Mika [02/Sep/06 06:30 PM]
The current resolution is that the thread reading the repository through ElmoSession is releasing the lock of the ElmoSession when reading the repository. An alternative solution would be if Sesame's SynchronizationSail would release the lock of the repository first and only then try to notify listeners of changes.

Change by Peter Mika [02/Sep/06 06:30 PM]
Field Original Value New Value
Status Open [ 1 ] Resolved [ 5 ]
Fix Version/s 0.3 [ 10228 ]
Resolution Fixed [ 1 ]

Change by Peter Mika [02/Sep/06 08:06 PM]
Field Original Value New Value
Status Resolved [ 5 ] Closed [ 6 ]