Project

General

Profile

Bug #70

Using a database-session in multiple threads can deadlock the server

Added by ronald - about 15 years ago. Updated about 15 years ago.

Status:
Closed
Priority:
High
Assignee:
Category:
Mulgara
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
fixed

Description

We have a shutdown handler on the client that closes open sessions;
<br/>
however, this shutdown handler is run is separate thread of its own.
<br/>
So an abort of the client while it's doing a db operation can generate
<br/>
the following sequence of events which leads to a deadlock:
<br/>

<br/>
{noformat}
<br/>
&nbsp;&nbsp;Thread-1                Thread-2
<br/>
&nbsp;&nbsp;set autocommit off
<br/>
&nbsp;&nbsp;...
<br/>
&nbsp;&nbsp;insert ...              close()
<br/>
{noformat}
<br/>

<br/>
(i.e. the insert and the close happen almost simultaneously). The
<br/>
resulting stack traces are roughly:
<br/>

<br/>
{noformat}
<br/>
&nbsp;&nbsp;Thread-1:
<br/>

<br/>
&nbsp;&nbsp;DatabaseSession.insert()
<br/>
&nbsp;&nbsp;&nbsp;&nbsp;DatabaseSession.execute()
<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MulgaraTransaxction.execute()
<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MulgaraTransaction.deactivate()                  &lt;---- monitor held
<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MulgaraTransaction.commitTransation()
<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MulgaraTransactionManager.transacactionComplete()
<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MulgaraTransactionManager.acquireMutex()   &lt;--- blocked
<br/>

<br/>
&nbsp;&nbsp;Thread-2:
<br/>

<br/>
&nbsp;&nbsp;DatabaseSession.close()
<br/>
&nbsp;&nbsp;&nbsp;&nbsp;MulgaraTransactionManager.rollbackCurrentTransactions()
<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MulgaraTransactionManager.acquireMutex()           &lt;--- mutex held
<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MulgaraTransaction.execute()
<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MulgaraTransaction.activate()                    &lt;--- blocked
<br/>
{noformat}
<br/>

<br/>

#1

Updated by Andrae Muys - about 15 years ago

Should be resolved in branches/mgr-70.
<br/>

<br/>
Due to the patch affecting the transaction logic will wait a week for review prior to merging into trunk and closing this bug.
#2

Updated by Andrae Muys - about 15 years ago

Merged to trunk in revision <a href="http://mulgara.org/trac/changeset/464">464</a>.

Also available in: Atom PDF