-
Notifications
You must be signed in to change notification settings - Fork 135
Description
I believe that I have observed GILProtected
(and thus, surprisingly, the GIL) allowing concurrent access to a RefCell
that it is protecting, thus causing a panic.
To investigate, I added a small wrapper around the RefCell
borrows, and observed:
...
22:46:18 [WARN] +++ 83a5671f6c6fbe9f ThreadId(3) generator_send_get
22:46:18 [WARN] --- 83a5671f6c6fbe9f
22:46:18 [WARN] +++ 81f2b10deb81ce84 ThreadId(3) key_for
22:46:18 [WARN] +++ a09bb2c19d0b0962 ThreadId(5) key_for
22:46:18 [ERROR] panic at 'already borrowed: BorrowMutError', /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447/src/libcore/cell.rs:878
22:46:18 [ERROR] Please set RUST_BACKTRACE=1, re-run, and then file a bug at https://github.com/pantsbuild/pants/issues.
22:46:18 [ERROR] panic at 'already mutably borrowed: BorrowError', /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447/src/libcore/cell.rs:798
22:46:18 [ERROR] Please set RUST_BACKTRACE=1, re-run, and then file a bug at https://github.com/pantsbuild/pants/issues.
22:46:18 [ERROR] panic at 'already mutably borrowed: BorrowError', /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447/src/libcore/cell.rs:798
22:46:18 [ERROR] Please set RUST_BACKTRACE=1, re-run, and then file a bug at https://github.com/pantsbuild/pants/issues.
22:46:18 [ERROR] panic at 'already mutably borrowed: BorrowError', /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447/src/libcore/cell.rs:798
22:46:18 [ERROR] Please set RUST_BACKTRACE=1, re-run, and then file a bug at https://github.com/pantsbuild/pants/issues.
22:46:18 [WARN] --- 81f2b10deb81ce84
...
What I believe that this is showing is that while ThreadId(3)
[1] is holding the GIL
with the acquisition id 81f2b10deb81ce84
, and before it has dropped the RefCell
(and thus definitely before it has dropped the GIL
), an attempt made by a different thread (ThreadId(5)
) to acquire the same RefCell
(acquisition a09bb2c19d0b0962
) fails. I do not know how to explain the further panics after the first one though.
This code is using cpython = 0.5
with the extension-module
feature.
Thank you for creating this library. I've thoroughly enjoyed porting this CFFI code to use it, and this is (hopefully) the last issue to track down before committing the port.
[1] these are all tokio runtime threads, but am not sure that that is relevant