[ZODB-Dev] error: release unlocked lock

Jeremy Hylton jeremy@zope.com
Mon, 6 Aug 2001 18:17:35 -0400 (EDT)


>>>>> "CW" == Chris Withers <chrisw@nipltd.com> writes:

  CW> Hi, This is with Zope 2.4.0b3 and ZEO 1.0b3:

> Traceback (most recent call last):
>     get_transaction().commit()
>    File "C:\Zope\2-4-0B~2\lib\python\ZODB\Transaction.py", line 301, in commit
>     j.tpc_begin(self)
>    File "C:\Zope\2-4-0B~2\lib\python\ZODB\Connection.py", line 633, in tpc_begin
>     self._storage.tpc_begin(transaction)
>    File "C:\zope\2-4-0b2_base\lib\python\ZEO\ClientStorage.py", line 482, in tpc_begin
>     self._commit_lock_release()
>  error: release unlocked lock

  CW> What does this mean?

Literally, it means that the commit lock was not held when release was
called.  If you get this bug, you should treat it like a ConflictError
(or other non-fatal ZODB exceptions) and retry the transaction.

  CW> Why is it happening? 

The commit lock is used to guarantee that only a single transaction
commits at one time if the client has multiple connections.  It is
normally released after a tpc_finish() or tpc_abort().

I expect it's happening because something is causing the ZEO
connection to be reset.  If a client disconnects from a storage
unexpectedly, say because a socket error occurs, the RPC layer cause
an exception to be returned from the next call and it will release the
commit lock.  The logic here is that if a transaction is currently
committing and the connection has closed, we need to be absolutely
sure that the commit lock is released.  Otherwise, the client would be
unable to commit new transactions.

The problem is that a socket error can occur while the client is
connecting.  If this happens, the release call can be made while the
lock isn't held.

This is a bug of sorts, but hopefully not to deep.  You should be
getting some other exception.

  CW> How can I make it stop?

How often are you seeing this problem?  I expected that socket errors
during connection would be quite rare.  I'd like to diagnose your
problem better and see if there is some other bug lurking that ought
to be fixed before ZEO 1.0 final.

One possibilty is the patch I've included below, which should prevent
the commit_lock_release error.  I haven't tested it much, so I
wouldn't try it in a production environment.  (More of a might-help
than a will-help.)

Jeremy