You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: please turn the WASI returnOnExit option to default true #46923
The current behaviour is for the WASI/WASM module to exit the process when __wasi_proc_exit is called. Not only that, currently it also allows the WASI module to control the exit code.
This seems like a capability that should be explicitly provided to the module rather than something that is on by default. It's unintuitive that a process running in a sandbox would have the ability to crash the entire app without the caller giving it explicit permission to do so.
This is particularly an issue when running 3rd party modules since you rarely have a complete idea on when and where the module might call __wasi_proc_exit and with what exit codes.
Returning instead of exitting when a sandboxed process finishes aligns better with the principles of least privilege and secure by default.
My only concern about making the default true is that the implementation of returnOnExit is currently pretty hacky. It monkey patches the WASI imports to throw a JavaScript Symbol that WASM cannot catch. If we were to make the default true, we should plumb the returnOnExit option to the native layer (ideally to here by making it an option on uvwasi_t).
EDIT: One thing that occurred to me is that we implemented the current hack because if proc_exit() did not exit the process, an assertion was raised (not from Node or uvwasi). If that assertion still exists, I'm not sure that we can cleanly return.
I brought this up in today's wasi team meeting. It sounds like our hacky approach is essentially the right way to go for now and we should change the default value of returnOnExit to true.
@cjihrig I'm happy to put together a PR to change the default. It is potentially breaking though so I'm wondering if we should mark it SemVer Major even though the feature is experimental. What do you think. Also my plan would be to put the PR together early next week so it would not make the cutoff for 20.x
Activity
bnoordhuis commentedon Mar 5, 2023
@nodejs/wasi
mhdawson commentedon Mar 28, 2023
@cjihrig what's your take on this? A default of
truemakes some sense to me but I'm sure you have more context.cjihrig commentedon Mar 28, 2023
I don't have strong feelings either way.
My only concern about making the default
trueis that the implementation ofreturnOnExitis currently pretty hacky. It monkey patches the WASI imports to throw a JavaScript Symbol that WASM cannot catch. If we were to make the defaulttrue, we should plumb thereturnOnExitoption to the native layer (ideally to here by making it an option onuvwasi_t).EDIT: One thing that occurred to me is that we implemented the current hack because if
proc_exit()did not exit the process, an assertion was raised (not from Node or uvwasi). If that assertion still exists, I'm not sure that we can cleanly return.cjihrig commentedon Mar 29, 2023
I brought this up in today's wasi team meeting. It sounds like our hacky approach is essentially the right way to go for now and we should change the default value of
returnOnExittotrue.mhdawson commentedon Mar 30, 2023
@cjihrig I'm happy to put together a PR to change the default. It is potentially breaking though so I'm wondering if we should mark it SemVer Major even though the feature is experimental. What do you think. Also my plan would be to put the PR together early next week so it would not make the cutoff for 20.x
tniessen commentedon Mar 30, 2023
How about making it semver-minor and not backporting to 19.x and below?
cjihrig commentedon Mar 30, 2023
WASI is still experimental in Node so we can change it at any time. But I do think not backporting it is a good idea.
mhdawson commentedon Mar 30, 2023
I like the suggestion as well. So we'll plan to mark semver-minor and then tag for don't backport to 19.x etc.
mhdawson commentedon Mar 30, 2023
I'll plan to submit a PR Friday or more likely Monday.
wasi: make returnOnExit true by default
mhdawson commentedon May 15, 2023
I think this can be closed as the PR to switch the default has landed. Let me know if you think that was not the right thing to do.