From ee87f34474605b5c2db2870621e8cb72c2043cae Mon Sep 17 00:00:00 2001 From: Bartosz Sosnowski Date: Thu, 27 Sep 2018 11:51:49 +0200 Subject: [PATCH] win,tty: fix uv_tty_close() Under some condition, uv_tty_close() would not stop console reads. This fixes that issue by first stopping read, then closing the handle. Fixes: https://github.com/nodejs/node/issues/22999 PR-URL: https://github.com/libuv/libuv/pull/2005 Reviewed-By: Santiago Gimeno Reviewed-By: Colin Ihrig Reviewed-By: Anna Henningsen --- src/win/tty.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/win/tty.c b/src/win/tty.c index dacb8a82..32ccf74c 100644 --- a/src/win/tty.c +++ b/src/win/tty.c @@ -2180,14 +2180,14 @@ void uv_process_tty_write_req(uv_loop_t* loop, uv_tty_t* handle, void uv_tty_close(uv_tty_t* handle) { assert(handle->u.fd == -1 || handle->u.fd > 2); + if (handle->flags & UV_HANDLE_READING) + uv_tty_read_stop(handle); + if (handle->u.fd == -1) CloseHandle(handle->handle); else close(handle->u.fd); - if (handle->flags & UV_HANDLE_READING) - uv_tty_read_stop(handle); - handle->u.fd = -1; handle->handle = INVALID_HANDLE_VALUE; handle->flags &= ~(UV_HANDLE_READABLE | UV_HANDLE_WRITABLE);