Open automorphis opened 1 year ago
This is an object lifetime problem that is exposing a subtle pylmdb bug. Keeping a reference to txn in BadDecoder causes a delayed finalization of txn.
As a temporary workaround, I found that adding decoder.txn = None
after decoder = BadDecoder(txn)
fixes it.
The performant solution is to create the txn context outside the loop.
I will investigate further.
I've encountered ReadersFullError
in a different context from the one I posted above. The error occurs if I read from and write to a single Environment
using more than one process. I didn't even try to isolate the error, but I did manage a workaround, which is basically "turn it off and on again".
If Environment.begin()
throws ReadersFullError
, then I do a "soft reset" in the process where the error occurred: I call Environment.close()
followed immediately by a call to lmdb.open()
. In my test cases, doing soft resets worked if I ran on only two processes. (A soft reset wasn't needed at all for a single process.)
A soft reset could fail in one of two ways: Either lmdb.open()
throws ReadersFullError
or the first call to Environment.begin()
does. If a soft reset fails in any process, I do a "hard reset":
Environment.close()
,multiprocessing.Event
,lock.mdb
),lmdb.open
(which recreates the lockfile),lmdb.open
.
Affected Operating Systems
Affected py-lmdb Version
1.3.0
py-lmdb Installation Method
sudo pip install lmdb
Using bundled or distribution-provided LMDB library?
Bundled
Distribution name and LMDB library version
0.9.29
Machine "free -m" output
Describe Your Problem
It took me quite some time to localize this problem and write a minimal reproducible example. The
json.JSONDecoder
class in the Python standard library doesn't work very well with LMDB, although I cannot understand why.The
json.JSONDecoder
class is a little idiosyncratic, in that you change the default decoding function by passing your own function toJSONDecoder.__init__
via the parameterobject_hook
. Frequently you needobject_hook
to call the instance-methodJSONDecoder.decode
, therefore it makes sense forobject_hook
to be an instance-method itself.The trouble is, if you have
object_hook
point to an instance-method, then callingEnvironment.begin
enough times will inexplicably eventually raiseReadersFullError
. Ifobject_hook
points to a function (not an instance-method), then no such error is raised.Example:
Errors/exceptions Encountered