-
Notifications
You must be signed in to change notification settings - Fork 625
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
proc_exit and traps do not stop thread executing blocking instructions #1910
Comments
@wenyongh @xujuntwt95329 @yamt after the initial discussion in #1869 (comment), any suggestion on the possible implementation of such a mechanism? |
I guess another approach would be to make all operations non-blocking in the host, but I'm not sure how much effort would that require (e.g. for WASI calls). Also, it might be problematic for user-defined native methods, so I think signals might be the way to go. // edit |
Two approaches:
|
in either approaches, i guess user-defined functions need to be adapted anyway. maybe pthread cancellation is another alternative to consider for posix-like platforms? |
Why is that? If we use signals, the thread running the user-defined function would be stopped.
But then we wouldn't return to the runtime after stopping a (possibly blocking) instruction. It may even be fine for spawn threads, but what if it's the main thread? |
I wonder what's the expected behavior of proc_exit? From what I see in the implementations, it just kills the process and doesn't allow for any resource cleanup (unlike C |
for example, if a user-defined function uses malloc(), it somehow needs to catch the signal to free() it.
sure. probably you're right it's even trickier than signals to use for this purpose. |
how would you address that? not sure if there's something we can do once the user-defined function is interrupted |
for example, we can make the user-defined functions deal with interruption by themselves. |
I wonder if we actually have to provide that capability; whereas C allows registering callback for |
for embedders like iwasm command, maybe it's enough to call host exit() and let the host os terminate threads. on the other hand, wamr, as a library, should provide a way to clean up associated resources. |
I didn't mean to call |
it's certainly possible to code host functions that way. however, it isn't how we code host functions right now. (including the ones within wamr tree like wasi) in other words, i prefer "if a host function doesn't implement async termination properly, it can't be async terminated (eg. possibly block forever)" over "if a host function doesn't implement async termination properly, it might cause problems like resource leak on async termination." |
In that case I guess this could be a compilation/runtime flag. We worked in parallel on making the |
i guess per host function flag makes more sense than a compilation/runtime flag. |
What do you mean by host function flag? |
eg. add a member to WASMFunctionImport to specify if it's safe to terminate the function that way. |
From #1869 (comment):
I wonder if that's something we could actually implement that at least for the |
do you mean to make these sleep-like functionalities wake up periodically internally so that it can check the extra termination conditions? i suppose it's the only choice for platforms where signal-like functionalities are not available. (that's why i did it that way for another runtime, where one of its main target doesn't have signals.) |
Yes, I was a bit confused when you said it's not approperiate approach for WAMR, but looks like it was just a misunderstanding, and we're on the same page. We'll implement that in addition to signals then. |
Sounds reasonable, for libc-wasi and internal code, we might change the implementation. But for user developed native library, it makes me a little confused: should runtime interrupt the thread running into native API by signal-like functionality, will it be not so friendly to developer? Should the developer be responsible for his behaviors? |
i said so about making "all i/o non-blocking". |
it's reasonable to make it an option.
|
Yes, I'm only talking about the
Yeah, I think we discussed it a few comments above; make it optional sounds reasonable to me. |
is anyone still working on this? |
Not currently, on my side at least. We started the effort on this branch bytecodealliance:dev/interrupt_block_insn. |
ok. thank you for an update. |
Unfortunately, not in the short term, I don't have any time scheduled to work on it. |
Send a signal whose handler is no-op to a blocking thread to wake up the blocking syscall with either EINTR equivalent or partial success. Unlike the approach taken in the `dev/interrupt_block_insn` branch (that is, signal + longjmp similarly to `OS_ENABLE_HW_BOUND_CHECK`), this PR does not use longjmp because: * longjmp from signal handler doesn't work on nuttx refer to apache/nuttx#10326 * the singal+longjmp approach may be too difficult for average programmers who might implement host functions to deal with See also #1910
Send a signal whose handler is no-op to a blocking thread to wake up the blocking syscall with either EINTR equivalent or partial success. Unlike the approach taken in the `dev/interrupt_block_insn` branch (that is, signal + longjmp similarly to `OS_ENABLE_HW_BOUND_CHECK`), this PR does not use longjmp because: * longjmp from signal handler doesn't work on nuttx refer to apache/nuttx#10326 * the singal+longjmp approach may be too difficult for average programmers who might implement host functions to deal with See also bytecodealliance#1910
With #1889,
proc_exit
and traps are properly propagated to all the threads in the process. Once a thread traps or callsproc_exit
, all the other threads are stopped.This is not true if the thread is executing a blocking operation (e.g.
sleep
,atomic.wait
). In that case, the blocking operation is not interrupted by the exception propagation process.Partial discussion here: #1869 (comment)
The text was updated successfully, but these errors were encountered: