Skip to content

Commit 6e3168d

Browse files

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/cli/vm.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,31 @@ static void initVM()
286286
uv_loop_init(loop);
287287
}
288288

289+
void on_uvWalkForShutdown(uv_handle_t* handle, void* arg)
290+
{
291+
if (!uv_is_closing(handle))
292+
uv_close(handle, NULL);
293+
}
294+
295+
static void uvShutdown() {
296+
uv_loop_t *loop = getLoop();
297+
int result = uv_loop_close(loop);
298+
if (result == UV_EBUSY)
299+
{
300+
uv_walk(loop, on_uvWalkForShutdown, NULL);
301+
uv_run(loop, UV_RUN_ONCE);
302+
}
303+
result = uv_loop_close(loop);
304+
if (result != 0) {
305+
fprintf(stderr, "could not close UV event loop completely");
306+
}
307+
}
308+
289309
static void freeVM()
290310
{
291311
ioShutdown();
292312
schedulerShutdown();
293-
294-
uv_loop_close(loop);
313+
uvShutdown();
295314
free(loop);
296315

297316
wrenFreeVM(vm);

0 commit comments

Comments
 (0)