From 357b9a773365436c360b61aeed4368dfa7cd2d26 Mon Sep 17 00:00:00 2001 From: Nikolai Vavilov Date: Sun, 4 Dec 2016 21:21:45 +0200 Subject: [PATCH] win, tty: fix crash on restarting with pending data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When reading from tty is restarted while there is pending data, uv_tty_read_start calls uv_insert_pending_req instead of uv_tty_queue_read to avoid losing keypresses. But reading can be stopped and restarted multiple times before the req is handled, which caused an assertion error. Setting the UV_HANDLE_READ_PENDING flag prevents uv_insert_pending_req from being called again until the req is handled. Fixes: https://github.com/nodejs/node/issues/9690 PR-URL: https://github.com/libuv/libuv/pull/1158 Reviewed-By: Ben Noordhuis Reviewed-By: Saúl Ibarra Corretgé --- src/win/tty.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/win/tty.c b/src/win/tty.c index fa80674e..1b7adf64 100644 --- a/src/win/tty.c +++ b/src/win/tty.c @@ -1004,6 +1004,9 @@ int uv_tty_read_start(uv_tty_t* handle, uv_alloc_cb alloc_cb, if (handle->tty.rd.last_key_len > 0) { SET_REQ_SUCCESS(&handle->read_req); uv_insert_pending_req(handle->loop, (uv_req_t*) &handle->read_req); + /* Make sure no attempt is made to insert it again until it's handled. */ + handle->flags |= UV_HANDLE_READ_PENDING; + handle->reqs_pending++; return 0; }