-
Notifications
You must be signed in to change notification settings - Fork 636
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
Recursive mutex returns ENORECOVERABLE (56) with wasi-threads #2466
Comments
OK I think I figured out what the issue is, it's about main() being assigned threadid of 0x3fffffff by default: https://github.com/WebAssembly/wasi-libc/blob/9f51a7102085ec6a6ced5778f0864c9af9f50000/libc-top-half/musl/src/env/__init_tls.c#L83
since it's not spawned by the runtime, it doesn't get assigned a tid by the host, so it stays 0x3fffffff. And then later on pthread_mutex_lock goes to this line because it's not a PTHREAD_MUTEX_NORMAL mutex but a recursive one: https://github.com/WebAssembly/wasi-libc/blob/9f51a7102085ec6a6ced5778f0864c9af9f50000/libc-top-half/musl/src/thread/pthread_mutex_trylock.c#L75 which then goes to here and sees that the mutex is being held by a thread with the id of 0x3fffffff which is an invalid thread id according to this code but it's actually our main(): https://github.com/WebAssembly/wasi-libc/blob/9f51a7102085ec6a6ced5778f0864c9af9f50000/libc-top-half/musl/src/thread/pthread_mutex_trylock.c#L24 The same issue can't be reproduced if it's two wasi-threads locking the same mutex. But when it's main() vs. a wasi-thread, it's a problem. |
the robust mutex logic in musl seems to assume that the bit 29 of TIDs is always zero for some reasons. from https://git.musl-libc.org/cgit/musl/commit/?id=099b89d3840c30d7dd962e18668c2e6d39f0c626 > note that the kernel ABI also reserves bit 29 > not to appear in any tid, i'm not sure if the assumption is true or not, given that FUTEX_TID_MASK is 0x3fffffff. anyway, when using non-default type of mutex like recursive mutex, it causes problems as we actually use TID 0x3fffffff for the main thread. as we don't support robust mutex anyway, this commit simply comments out the problematic condition. fixes: bytecodealliance/wasm-micro-runtime#2466
the robust mutex logic in musl seems to assume that the bit 29 of TIDs is always zero for some reasons. from https://git.musl-libc.org/cgit/musl/commit/?id=099b89d3840c30d7dd962e18668c2e6d39f0c626 > note that the kernel ABI also reserves bit 29 > not to appear in any tid, i'm not sure if the assumption is true or not, given that FUTEX_TID_MASK is 0x3fffffff. anyway, when using non-default type of mutex like recursive mutex, it causes problems as we actually use TID 0x3fffffff for the main thread. as we don't support robust mutex anyway, this commit simply comments out the problematic condition. fixes: bytecodealliance/wasm-micro-runtime#2466
@denizsokmen it looks like that was a wasi-libc issue. Can we resolve the ticket now given the fix has already been merged? |
@loganek Yes, that fixes the issue |
I've encountered an issue where two threads locking the same recursive mutex secretly fails. Also I've noticed that the lock failure only happens from the spawned thread.
Here's a minimal reproduction case where the program will abort if lock returns non-zero:
Where test.cpp is:
The text was updated successfully, but these errors were encountered: