-
Notifications
You must be signed in to change notification settings - Fork 3.8k
win,tty: fix uv_tty_set_mode race conditions #1054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use a multi-line comment here, like it was before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
|
Updated, PTAL |
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 */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: can you adjust the comment style as below?
saghul
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a style nit. A test would be nice though, not sure how possible that is. @bzoz?
|
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. |
|
LGTM with a leap of faith ;-) |
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]>
|
Cheers, Bartosz, landed in 8414403. |
This reverts commit f59b888 now that the libuv update containing the proper fix has landed in 63243bc. Ref: libuv/libuv#1054 Ref: nodejs#7837
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]>
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]>
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]>
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]>
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]>
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]>
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]>
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]>
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]>
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]>
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