win,tty: fix uv_tty_set_mode race conditions#1054
Closed
bzoz wants to merge 3 commits intolibuv:v1.xfrom
Closed
Conversation
Additional synchronization is needed to ensure that the program cannot modify the screen state while a line read is getting cancelled. Also, we need to stop any pending reads *before* calling SetConsoleMode, or a call to ReadConsole could start while the console is still in raw mode. Credit: orangemocha - Alexis Campailla <[email protected]> Fixes: nodejs/node#7837
saghul
reviewed
Sep 16, 2016
Member
saghul
left a comment
There was a problem hiding this comment.
Left some comments. Can a test for this be written?
src/win/tty.c
Outdated
| /* thread and release it in another thread. Using a semaphore ensures that */ | ||
| /* in such scenario the main thread will still block when trying to acquire */ | ||
| /* the lock. */ | ||
| static HANDLE uv_tty_output_lock; |
Member
There was a problem hiding this comment.
Can we use a uv_sem_t here instead?
src/win/tty.c
Outdated
| if (InterlockedOr(&uv__restore_screen_state, 0)) { | ||
| HANDLE active_screen_buffer = CreateFileA("conout$", | ||
| if (status == TRAP_REQUESTED) { | ||
| /* If we canceled the read by sending a VK_RETURN event, restore the */ |
Member
There was a problem hiding this comment.
Please use a multi-line comment here, like it was before.
Member
Author
There was a problem hiding this comment.
What style to use? This:
/* comment comment
* comment comment
*/
or this:
/* comment comment
comment comment */
?
|
|
||
| assert(!(handle->flags & UV_HANDLE_CANCELLATION_PENDING)); | ||
|
|
||
| /* Hold the output lock during the cancellation, to ensure that further |
Member
Author
|
Updated, PTAL |
saghul
reviewed
Sep 16, 2016
src/win/tty.c
Outdated
| static int uv_tty_virtual_width = -1; | ||
|
|
||
| static CRITICAL_SECTION uv_tty_output_lock; | ||
| /* We use a semaphore rather than a mutex or critical section because in */ |
Member
There was a problem hiding this comment.
style: can you adjust the comment style as below?
Member
Author
|
Updated the comment style. I don't think that a test for this is possible, at least I don't know how to make one. |
Member
|
LGTM with a leap of faith ;-) |
saghul
pushed a commit
that referenced
this pull request
Sep 18, 2016
Additional synchronization is needed to ensure that the program cannot modify the screen state while a line read is getting cancelled. Also, we need to stop any pending reads *before* calling SetConsoleMode, or a call to ReadConsole could start while the console is still in raw mode. Credit: @orangemocha - Alexis Campailla <[email protected]> Fixes: nodejs/node#7837 PR-URL: #1054 Reviewed-By: Saúl Ibarra Corretgé <[email protected]>
Member
|
Cheers, Bartosz, landed in 8414403. |
2 tasks
addaleax
added a commit
to addaleax/node
that referenced
this pull request
Oct 27, 2016
This reverts commit f59b888 now that the libuv update containing the proper fix has landed in 63243bc. Ref: libuv/libuv#1054 Ref: nodejs#7837
addaleax
added a commit
to nodejs/node
that referenced
this pull request
Nov 16, 2016
This reverts commit f59b888 now that the libuv update containing the proper fix has landed in 63243bc. Ref: libuv/libuv#1054 Ref: #7837 PR-URL: #8645 Reviewed-By: Nikolai Vavilov <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Bartosz Sosnowski <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
italoacasas
pushed a commit
to italoacasas/node
that referenced
this pull request
Jan 18, 2017
This reverts commit f59b888 now that the libuv update containing the proper fix has landed in 63243bc. Ref: libuv/libuv#1054 Ref: nodejs#7837 PR-URL: nodejs#8645 Reviewed-By: Nikolai Vavilov <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Bartosz Sosnowski <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
MylesBorins
pushed a commit
to nodejs/node
that referenced
this pull request
Jan 23, 2017
This reverts commit f59b888 now that the libuv update containing the proper fix has landed in 63243bc. Ref: libuv/libuv#1054 Ref: #7837 PR-URL: #8645 Reviewed-By: Nikolai Vavilov <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Bartosz Sosnowski <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
MylesBorins
pushed a commit
to nodejs/node
that referenced
this pull request
Jan 24, 2017
This reverts commit f59b888 now that the libuv update containing the proper fix has landed in 63243bc. Ref: libuv/libuv#1054 Ref: #7837 PR-URL: #8645 Reviewed-By: Nikolai Vavilov <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Bartosz Sosnowski <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
italoacasas
pushed a commit
to italoacasas/node
that referenced
this pull request
Jan 24, 2017
This reverts commit f59b888 now that the libuv update containing the proper fix has landed in 63243bc. Ref: libuv/libuv#1054 Ref: nodejs#7837 PR-URL: nodejs#8645 Reviewed-By: Nikolai Vavilov <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Bartosz Sosnowski <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
italoacasas
pushed a commit
to italoacasas/node
that referenced
this pull request
Jan 27, 2017
This reverts commit f59b888 now that the libuv update containing the proper fix has landed in 63243bc. Ref: libuv/libuv#1054 Ref: nodejs#7837 PR-URL: nodejs#8645 Reviewed-By: Nikolai Vavilov <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Bartosz Sosnowski <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
MylesBorins
pushed a commit
to nodejs/node
that referenced
this pull request
Jan 31, 2017
This reverts commit f59b888 now that the libuv update containing the proper fix has landed in 63243bc. Ref: libuv/libuv#1054 Ref: #7837 PR-URL: #8645 Reviewed-By: Nikolai Vavilov <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Bartosz Sosnowski <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
MylesBorins
pushed a commit
to nodejs/node
that referenced
this pull request
May 16, 2017
This reverts commit f59b888 now that the libuv update containing the proper fix has landed in 63243bc. Ref: libuv/libuv#1054 Ref: #7837 PR-URL: #8645 Reviewed-By: Nikolai Vavilov <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Bartosz Sosnowski <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
MylesBorins
pushed a commit
to nodejs/node
that referenced
this pull request
May 18, 2017
This reverts commit f59b888 now that the libuv update containing the proper fix has landed in 63243bc. Ref: libuv/libuv#1054 Ref: #7837 PR-URL: #8645 Reviewed-By: Nikolai Vavilov <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Bartosz Sosnowski <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
andrew749
pushed a commit
to michielbaird/node
that referenced
this pull request
Jul 19, 2017
This reverts commit f59b888 now that the libuv update containing the proper fix has landed in 63243bc. Ref: libuv/libuv#1054 Ref: nodejs/node#7837 PR-URL: nodejs/node#8645 Reviewed-By: Nikolai Vavilov <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Bartosz Sosnowski <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Additional synchronization is needed to ensure that the program cannot modify the screen state while a line read is getting cancelled.
Also, we need to stop any pending reads before calling
SetConsoleMode, or a call toReadConsolecould start while the console is still in raw mode.We also switch to use a semaphore rather than a critical section because in some cases (
uv__cancel_read_console) we need take the lock in the main thread and release it in another thread. Using a semaphore ensures that in such scenario the main thread will still block when trying to acquire the lockCredit: orangemocha - Alexis Campailla [email protected]
Fixes: nodejs/node#7837