This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Closing dbenv first bsddb doesn't release locks & segfau
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: gregory.p.smith Nosy List: gregory.p.smith, janeaustine50, nnorwitz
Priority: normal Keywords:

Created on 2003-08-14 05:13 by janeaustine50, last changed 2022-04-10 16:10 by admin. This issue is now closed.

Messages (5)
msg17773 - (view) Author: Jane Austine (janeaustine50) Date: 2003-08-14 05:13
There is a test code named test_env_close in 
bsddb/test, but it
doesn't test the case thoroughly. There seems to be a 
bug in closing
the db environment first -- the lock is not released, and 
sometimes it
seg-faults.

Following is the code that shows this bug.

<code>
import os
from bsddb import db

dir,dbname='test_dbenv','test_db'

def getDbEnv(dir):
    try:
        os.mkdir(dir)
    except:
        pass
    dbenv = db.DBEnv()
    dbenv.open(dir, db.DB_INIT_CDB| db.DB_CREATE 
|db.DB_INIT_MPOOL)
    return dbenv

def getDbHandler(db_env,db_name):
    d = db.DB(dbenv)
    d.open(db_name, db.DB_BTREE, db.DB_CREATE)
    return d

dbenv=getDbEnv(dir)
assert dbenv.lock_stat()['nlocks']==0
d=getDbHandler(dbenv,dbname)
assert dbenv.lock_stat()['nlocks']==1
try:
    dbenv.close()
except db.DBError:
    pass
else:
    assert 0

del d
import gc
gc.collect()
dbenv=getDbEnv(dir)
assert dbenv.lock_stat()['nlocks']==0,'number of current 
locks should
be 0' #this fails
</code>

If you close dbenv before db handler, the lock is not 
released.
Moreover, try this with dbshelve and it segfaults.

<code>
>>> from bsddb import dbshelve
>>> dbenv2=getDbEnv('test_dbenv2')
>>> d2=dbshelve.open(dbname,dbenv=dbenv2)
>>> try:
...     dbenv2.close()
... except db.DBError:
...     pass
... else:
...     assert 0
... 
>>>
>>> 
Exception bsddb._db.DBError: (0, 'DBEnv object has 
been closed') in
Segmentation fault
</code>

Tested on:
 1. linux with Python 2.3 final, Berkeley DB 4.1.25
 2. windows xp with Python 2.3 final (with _bsddb that 
comes along)
msg17774 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2004-06-16 03:14
Logged In: YES 
user_id=33168

Greg do you know anything about this?  Is it still a problem?
msg17775 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2004-06-16 22:18
Logged In: YES 
user_id=413

Yes this bug is still there.  A "workaround" is just a
"don't do that" when it comes to closing sleepycat DBEnv
objects while there are things using them still open.  I
believe we can prevent this...

One proposal: internally in _bsddb.c DBEnv could be made to
keep a weak reference to all objects created using it (DB
and DBLock objects) and refuse to call the sleepycat close()
method if any still exist (overridable using a force=1 flag).
msg17776 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2006-01-24 08:04
Logged In: YES 
user_id=33168

Jane could try the patch in bug 1413192 to see if it fixes
your problem?
msg17777 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2006-01-25 06:05
Logged In: YES 
user_id=33168

Assuming this was fixed by the patch.
History
Date User Action Args
2022-04-10 16:10:39adminsetgithub: 39066
2003-08-14 05:13:49janeaustine50create