Closed Simon-Laux closed 1 year ago
We had a similar problem (with concurrent-queue) previously:
As far as I remember, I carefully checked all the code in concurrent-queue
and decided there are no bugs there.
The bug was fixed by not using objects after freeing them: https://github.com/deltachat/deltachat-core-rust/issues/3430
So I guess there is an use-after-free issue too.
windows ci just watched this issue, too:
I'm rerunning it in hope that it fixes itself for that ci run
Since we don't use any unsafe
code, I think it's a bug in napi
and should be reported upstream. But first we need a minimal example, because if we just report to napi
devs that this repo is crashing, doubt anyone will dig into deltachat-core-rust to figure out how event loop is implemented and where tokio runtime is initialized.
So the plan is roughly:
Ideally this can be reduced to creating some objects resembling account manager, Arc
s, a spawned task and some channels for events.
It is related to the event loop, I suspect it is not destroyed / shutdown correctly as the bot example works fine.
https://github.com/deltachat/napi-jsonrpc/blob/ba3750cba9403ff649a7c16b61f7d8226210ede0/src/lib.rs#L38-L50
when commenting it out the test gets more stable and I have not gotten the issue without it. The issue:
more in https://github.com/deltachat/napi-jsonrpc/blob/ba3750cba9403ff649a7c16b61f7d8226210ede0/panic%20-%20problem the
len
andindex
change, I have seen such small values, but also really large ones already.I don't know how to shut down the event loop cleanly when destroying, garbage collecting the Account Manager, because:
napi-rs hides the join handle that is normaly returned by RT.spawn.
also destruction methods (both from napirs trait and the drop trait are synchronous, so nothing async can be run there without access to the block_on function of the tokio runtime which napi-rs also hides)
another option would be a future race in the event loop, where its completed once any future completes and one of the future being a thread safe boolean that gets set during shutdown, loosely similar to how its done in the rust echo bot:
https://github.com/deltachat-bot/echo/blob/088f4bf6dd5646e243cbe9825610f6176a7a14f9/rust/src/main.rs#L116-L124
To reproduce: run
yarn test
many times, sometimes it panics.