From c6e3e717b8356cabdaa274a141e8e2ba17b7bcc7 Mon Sep 17 00:00:00 2001 From: lander0s Date: Wed, 10 Jun 2020 19:27:44 -0700 Subject: [PATCH] win,tty: fix deadlock caused by inconsistent state The variable uv__read_console_status is left as IN_PROGRESS when the operation is canceled ahead of time by the main thread requesting a trap (race condition?). This confuses the next call to uv__cancel_read_console(...) causing a deadlock due to a semaphore acquisition that is never released by the reading thread. Setting the status variable back to COMPLETE or NOT_STARTED fixes the issue. Ref: https://github.com/nodejs/node/issues/32999 PR-URL: https://github.com/libuv/libuv/pull/2882 Reviewed-By: Bartosz Sosnowski (cherry picked from commit aeab873bbe4efb94baacc17ca9ab38a45009e6e8) --- src/win/tty.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/win/tty.c b/src/win/tty.c index 2e03026b515..056b9699078 100644 --- a/src/win/tty.c +++ b/src/win/tty.c @@ -485,6 +485,7 @@ static DWORD CALLBACK uv_tty_line_read_thread(void* data) { status = InterlockedExchange(&uv__read_console_status, IN_PROGRESS); if (status == TRAP_REQUESTED) { SET_REQ_SUCCESS(req); + InterlockedExchange(&uv__read_console_status, COMPLETED); req->u.io.overlapped.InternalHigh = 0; POST_COMPLETION_FOR_REQ(loop, req); return 0;