Skip to content

Commit

Permalink
win,tty: fix deadlock caused by inconsistent state
Browse files Browse the repository at this point in the history
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: nodejs/node#32999

PR-URL: libuv#2882
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
  • Loading branch information
lander0s authored and bzoz committed Jun 15, 2020
1 parent ff3ab31 commit aeab873
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/win/tty.c
Expand Up @@ -517,6 +517,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;
Expand Down

0 comments on commit aeab873

Please sign in to comment.