-
Notifications
You must be signed in to change notification settings - Fork 763
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
Core dumped when initializing a pyclass on Linux only #1120
Comments
I've rewritten the test case to separate each line, and see dbg statements from Pyo3 in-between. def test_compile_wat():
print("--> store\n")
store = Store()
print("/ store\n");
print("--> module\n")
module = Module(store, '(module)')
print("/ module\n")
print("--> isinstance")
assert isinstance(module, Module)
print("/ isinstance") The |
I can reproduce the issue locally, this reliably causes crashes: >>> from wasmer import Store, Module
>>> store = Store()
>>> module = Module(store, '(module)')
>>> del store
>>> del module
[1] 32123 abort (core dumped) ipython Switching the order of the I took a quick look at the Store and Module implementations but didn't have to time to dig through all of that whether |
So. The destructor of ManuallyDrop::drop(&mut self.inner.value);
self.dict.clear_dict(py);
self.weakref.clear_weakrefs(self.as_ptr(), py);
self.inner.ob_base.py_drop(py); So the destructor Then, the destructor of
Second run is OK. Having To be continued :-p. |
Most definitely not related to It's not even necessary to delete any variables, it sometimes crashes while cleaning up after exiting Python: >>> from wasmer import Store, Module
>>> store = Store()
>>> module = Module(store, '(module)')
Do you really want to exit ([y]/n)?
[1] 7632 abort (core dumped) ipython |
Yes, I come to the same conclusion. |
I'm actually seeing failure before unsafe fn py_drop(&mut self, py: Python) {
println!("enter pydrop");
ManuallyDrop::drop(&mut self.inner.value);
println!("dropped");
self.dict.clear_dict(py);
println!("cleared dict");
self.weakref.clear_weakrefs(self.as_ptr(), py);
self.inner.ob_base.py_drop(py);
}
|
That's what I'm digging right now. It doesn't seem related to Pyo3. Want to be sure before closing the issue :-). |
Many thanks @sebpuetz for helping investigate this! I don't see any obvious red flags from the source I just scanned. Are you able to reproduce this issue using It doesn't seem like this is a PyO3 issue at the moment, but happy to be proved wrong! |
That reminder made me take another look and it's not related to pyo3: #[test]
fn test2() {
let store = wasmer::Store::default();
let module = wasmer::Module::new(&store, "(module)").unwrap();
mem::drop(store);
mem::drop(module); // abort
} Stepping through the code in a debugger shows that the abort happens while dropping A fix is switching the order of the struct members in pub struct Module {
artifact: Arc<dyn Artifact>,
store: Store,
}
Allocation happens here: https://github.com/wasmerio/wasmer/blob/80290e48055655a63f05f2c329f2ace4adbc712f/lib/engine-jit/src/artifact.rs#L165-L166 Subverting lifetimes happens here: https://github.com/wasmerio/wasmer/blob/80290e48055655a63f05f2c329f2ace4adbc712f/lib/engine-jit/src/unwind/systemv.rs#L86 Assuming dead-pointers are still alive happens here: https://github.com/wasmerio/wasmer/blob/80290e48055655a63f05f2c329f2ace4adbc712f/lib/engine-jit/src/unwind/systemv.rs#L104-L106 I think you can close this, I'll open an issue over at wasmer. |
Superb sleuthing, thanks again! |
It's not related to Pyo3. I found the bug in Wasmer, wasmerio/wasmer#1581. Thanks for your time and sorry for the noise! |
rustc --version
): 1.45.2version = "0.x.y"
withgit = "https://github.com/PyO3/pyo3")?
: No.So, this bug is weird. It happens only on Linux (not on macOS nor Windows, I've tested).
I'm rewriting
python-ext-wasm
, a project that uses Pyo3. Here is the PR, wasmerio/wasmer-python#212.To build:
To test, comment everything inside the
tests/test_module.py
file except line 20 to 21 (def test_compile_wat
) as it is a small test case involving very few lines of code, and it fails.Then run with:
$ just test tests/test_module.py … Fatal Python error: Aborted [stack trace] Aborted (core dumped)
I'm currently tracing what happens. The
Module
pyclass is defined as:struct Module { inner: wasmer::Module }
. If I change toinner: u32
, it works. So it seems thatwasmer::Module
is not liked by Pyo3 or Python.The
Module
pyclass is defined insrc/module.rs
. Thewasmer::Module
is defined in https://github.com/wasmerio/wasmer/blob/80290e48055655a63f05f2c329f2ace4adbc712f/lib/api/src/module.rs#L33-L37 (for the record:struct Module { store: Store, artifact: Arc<dyn Artifact> }
).I'm digging for the moment.
PyClassInitiliazer.create_cell_from_subtype
is working so far. Since it is the last thing returned by the__new__
implementation, I don't understand where it can fail. Or maybe the class isn't well initialized.Important: It works on macOS and Windows. It fails only on Linux. It's not random, but for some
Module
(Python class), it works! If you take thedef test_exports()
test case, in the sametest_module.py
file, you'll see that it works.It drives me crazy. Help :-).
The text was updated successfully, but these errors were encountered: