Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don’t corrupt the yyjson pool when reentering orjson.loads #427

Closed
wants to merge 1 commit into from

Conversation

andersk
Copy link
Contributor

@andersk andersk commented Sep 8, 2023

orjson.loads may allocate a Python object that triggers a garbage collection that invokes a destructor that calls orjson.loads again. Or the destructor may release the GIL so a different thread can call orjson.loads. To remain safe under such reentrancy, we need to avoid reinitializing the yyjson pool while it might still be in use. The simplest fix is to initialize the yyjson pool only once, like we did before commit e9b745e.

orjson.loads may allocate a Python object that triggers a garbage
collection that invokes a destructor that calls orjson.loads again.
Or the destructor may release the GIL so a different thread can call
orjson.loads.  To remain safe under such reentrancy, we need to avoid
reinitializing the yyjson pool while it might still be in use.  The
simplest fix is to initialize the yyjson pool only once, like we did
before commit e9b745e.

Fixes ijl#415.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
@ijl
Copy link
Owner

ijl commented Sep 8, 2023

Cherry-picked as e79abe6, thank you.

@ijl ijl closed this Sep 8, 2023
@andersk andersk deleted the reentrancy branch September 8, 2023 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3.9.4 has a threading issue
2 participants