-
Notifications
You must be signed in to change notification settings - Fork 24
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
Segmentation fault caused by Asyncio concurrent access to properties #210
Comments
In general we don't guarantee libzfs is even thread-safe, let alone reentrant. Since you have 200 tasks on an executor that probably has fewer than 200 threads, there are multiple tasks trying to use the same thread-local buffer
A potential solution I think would be to use an asyncio.Lock around async use of py-libzfs. If I understand asyncio.Lock correctly this will block tasks on the same thread but not on different threads, preventing simultaneous use of the thread-local static buffer. At least that's how I'm interpreting "not thread-safe" in the documentation. Or maybe some other mechanism is a better fit. |
I'll be taking your feedback into account to find the least-cost path while protecting py-libzfs for async. If this is something that interest you, I would be happy to share with you my findings and contribute them back to the upstream. If you believe you don't want to support asyncio on libzfs (which is fine, no argument here whatsoever), we will propose a fork. In either case your feedback would be invaluable. Depending on the course of action (official support or not) feel free to close this issue (or not). If you think of anyone who could help by reviewing this, this would come a long way. In the meantime, I thank you for your time. |
Hi @vindict-gh . We are definitely open for you to contribute the required changes to make this safe to be used with asyncio. We would, of course, have to review it closely. |
Just keep in mind there are 2 "gotchas" to look out for that Ryan commented above. 1.Reentrancy Some of the libzfs methods do not use reentrant safe syscalls and so that will have to be considered when making any changes. |
OS : Debian Bullseye (11)
Kernel : 5.10.0-15-amd64
ZFS Version : 2.1.4-1~bpo11+1
Impacted version :
release/22.02.4
While using py-libzfs with Asyncio, accessing properties of several datasets concurrently causes a segfault in accessing getmntany to retrieve the 'mountpoint' property.
We were able to reproduce easily with this simple script.
Below, the
gdb --args python3 test_script.py
output :I was able to prevent the segfault by reactivating the GIL during
libzfs.zfs_prop_get()
call inZFSProperty.refresh()
and inZFS.__dataset_handles()
I do believe that the
nogil
behaviour was intended. Could you please explain why thenogil
is important for you here ? If you want I already have a patch and can provide a PR to re-acquire the GIL upon libzfs.zfs_prop_get() calls.If any information is missing I remain at your disposal.
The text was updated successfully, but these errors were encountered: