Skip to content
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

vm: make runtime shutdown more resilient #393

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ static void uv__stop(uv_async_t *handle) {
uv_stop(&qrt->loop);
}

static void uv__walk(uv_handle_t* handle, void* arg) {
if (!uv_is_closing(handle))
uv_close(handle, NULL);
}

void TJS_DefaultOptions(TJSRunOptions *options) {
static TJSRunOptions default_options = { .mem_limit = -1, .stack_size = TJS__DEFAULT_STACK_SIZE };

Expand Down Expand Up @@ -254,6 +259,8 @@ void TJS_FreeRuntime(TJSRuntime *qrt) {
/* Destroy WASM runtime. */
m3_FreeEnvironment(qrt->wasm_ctx.env);

uv_walk(&qrt->loop, uv__walk, NULL);

/* Cleanup loop. All handles should be closed. */
int closed = 0;
for (int i = 0; i < 5; i++) {
Expand All @@ -266,8 +273,8 @@ void TJS_FreeRuntime(TJSRuntime *qrt) {
#ifdef DEBUG
if (!closed)
uv_print_all_handles(&qrt->loop, stderr);
#endif
CHECK_EQ(closed, 1);
#endif

free(qrt);
}
Expand Down
Loading