aviramha/ormsgpack

'Lazy instance has previously been poisoned' in asynchronous environment

Quitlox opened this issue · 6 comments

Hi there,

First of all, thanks for your work on this package.

We use this package in an asynchronous environment (we use the asyncio library) and have encountered a problem. Sometimes, when calling ormsgpack.packb the following error is thrown:
thread '<unnamed>' panicked at 'Lazy instance has previously been poisoned', /home/quitlox/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/once_cell-1.17.0/src/lib.rs:746:25

After some testing, we found this is due to ormsgpack using the unsync version of once_cell (which is not thread safe). Switching to the sync version of once_cell resolves the issue.

Is there a particular reason the unsync version of once_cell is used? If not, I can make a PR to switch to the sync version and resolve this bug.

@aviramha, any thought from your end?

If you are fine with the suggested change we'll submit a PR.

Thanks for the report. And thanks for tagging me as I didn't get a notification for the issue.
I'm pretty sure this usage comes from upstream (orjson) and can guess as many low level things done there it's for optimization and performance.
I would suggest asking the question upstream while trying to understand how to reproduce and trigger this exactly since I assume it's a GIL issue of some sort?

I see that orjson uses sync calls in

https://github.com/ijl/orjson/blob/master/src/typeref.rs#L8

Great! You're welcome to send a PR.

@aviramha I submitted a PR!

@aviramha, thanks for your support, much appreciated!