-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don’t corrupt the yyjson pool when reentering orjson.loads
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 #415. Signed-off-by: Anders Kaseorg <[email protected]>
- Loading branch information
Showing
3 changed files
with
40 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import orjson | ||
|
||
|
||
class C: | ||
c: "C" | ||
|
||
def __del__(self): | ||
orjson.loads('"' + "a" * 10000 + '"') | ||
|
||
|
||
def test_reentrant(): | ||
c = C() | ||
c.c = c | ||
del c | ||
|
||
orjson.loads("[" + "[]," * 1000 + "[]]") |