-
Notifications
You must be signed in to change notification settings - Fork 3.8k
win,tty: improve SIGWINCH support #1408
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
src/win/tty.c
Outdated
| /* Store the global tty output handle. This handle is used by TTY read */ | ||
| /* streams to update the virtual window when a CONSOLE_BUFFER_SIZE_EVENT */ | ||
| /* is received. */ | ||
| uv_tty_console_handle = handle; |
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.
we need to hold the uv_tty_output_lock at least here, this is not thread safe.
a805728 to
6418a8a
Compare
|
@saghul updated (and rebased), PTAL |
src/win/tty.c
Outdated
| * handle signalling SIGWINCH | ||
| */ | ||
|
|
||
| static HANDLE uv_tty_console_handle = INVALID_HANDLE_VALUE; |
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 you prefix these with uv__ instead? I know src/win is not very consistent in this regard, but let's try to be, for new code.
| WINEVENT_OUTOFCONTEXT)) | ||
| uv_fatal_error(GetLastError(), "SetWinEventHook"); | ||
|
|
||
| while (GetMessage(&msg, NULL, 0, 0)) { |
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.
how is this intettupted?
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.
ping
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.
I've described it in #1408 (comment)
src/win/tty.c
Outdated
| height = screen_buffer_info.srWindow.Bottom - screen_buffer_info.srWindow.Top + 1; | ||
|
|
||
| if (width != uv_tty_console_width || height != uv_tty_console_height) { | ||
| uv_tty_console_width = width; |
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.
this needs to hold the lock
src/win/tty.c
Outdated
| if (!GetConsoleScreenBufferInfo(uv_tty_console_handle, &screen_buffer_info)) | ||
| uv_fatal_error(GetLastError(), "GetConsoleScreenBufferInfo"); | ||
|
|
||
| uv_tty_console_width = screen_buffer_info.dwSize.X; |
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.
this needs to hold the lock
b7e21a5 to
6048b42
Compare
|
@saghul I've updated the change, PTAL. I've moved the The loop in |
|
CI (with correct branch name): https://ci.nodejs.org/view/libuv/job/libuv-test-commit/368/ |
|
Ping? |
src/win/tty.c
Outdated
| MSG msg; | ||
|
|
||
| if (!GetConsoleScreenBufferInfo(uv__tty_console_handle, &sb_info)) | ||
| uv_fatal_error(GetLastError(), "GetConsoleScreenBufferInfo"); |
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.
Is this really fatal? Can't we live if it fails?
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.
I guess we can, but there is no way to signal the user that this failed, and that SIGWINCH will not work.
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.
I know, but so what? it fails, we move on. I think it's far better than crashing!
src/win/tty.c
Outdated
| 0, | ||
| 0, | ||
| WINEVENT_OUTOFCONTEXT)) | ||
| uv_fatal_error(GetLastError(), "SetWinEventHook"); |
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
| WINEVENT_OUTOFCONTEXT)) | ||
| uv_fatal_error(GetLastError(), "SetWinEventHook"); | ||
|
|
||
| while (GetMessage(&msg, NULL, 0, 0)) { |
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.
ping
src/win/tty.c
Outdated
| int width, height; | ||
|
|
||
| if (!GetConsoleScreenBufferInfo(uv__tty_console_handle, &sb_info)) | ||
| uv_fatal_error(GetLastError(), "GetConsoleScreenBufferInfo"); |
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
|
[biased scepticism, but I'm open to be persuaded] Do we know of any interesting uses for this event? (honest question) |
|
I hate that broken behavior. If we can do better, why not? Also, Node is not the entire universe other projects are not going to read those disclaimers. |
|
@saghul I've removed the |
src/win/tty.c
Outdated
| NULL, | ||
| WT_EXECUTELONGFUNCTION); | ||
| if (r == 0) | ||
| abort(); |
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.
i don't think this should be fatal
src/win/tty.c
Outdated
| static void uv__determine_vterm_state(HANDLE handle); | ||
|
|
||
| void uv_console_init(void) { | ||
| int r; |
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.
you can declare r inside the if where it's used.
|
Updated, PTAL |
|
Ping? |
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
Add SetWinEventHook for EVENT_CONSOLE_LAYOUT for better detection of console resize events. Ref: nodejs/node#13197 PR-URL: libuv#1408 Reviewed-By: Saúl Ibarra Corretgé <[email protected]>
aa3dd00 to
0b9959e
Compare
|
Unrelated failures, rerun Windows CI: https://ci.nodejs.org/job/libuv-test-commit-windows/548/. |
Add SetWinEventHook for EVENT_CONSOLE_LAYOUT for better detection of console resize events. Ref: nodejs/node#13197 PR-URL: #1408 Reviewed-By: Saúl Ibarra Corretgé <[email protected]>
|
Landed in 6ad1e81 |
This commit removes unused variables left over from 6ad1e81. Refs: #1408 PR-URL: #1571 Reviewed-By: Santiago Gimeno <[email protected]> Reviewed-By: Bartosz Sosnowski <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
Continuing improvement of SIGWINCH from PR libuv#2308. Running SetWinEventHook without filtering for the specific PIDs has significant impact on the performance of the entire system. This PR changes the way SIGWINCH is handled. The SetWinEventHook callback now signals a separate thread, uv__tty_console_resize_watcher_thread. This thread calls uv__tty_console_signal_resize() which checks if the console was actually resized. The uv__tty_console_resize_watcher_thread makes sure to not to call the uv__tty_console_signal_resize function more than 30 times per second. The SetWinEventHook will not be installed, if the PID of the conhost.exe process that owns the console window cannot be determinated. This can happen when a 32bit libuv app is running on a 64bit Windows. For such cases PR libuv#1408 is partially reverted - when tty reads WINDOW_BUFFER_SIZE_EVENT, it will also trigger a call to uv__tty_console_signal_resize(). This will also help when the app is running under console emulators. Documentation was alos updated to reflect that. Refs: microsoft/terminal#1811 Refs: microsoft/terminal#410 Refs: libuv#2308
Continuing improvement of SIGWINCH from PR libuv#2308. Running SetWinEventHook without filtering for the specific PIDs has significant impact on the performance of the entire system. This PR changes the way SIGWINCH is handled. The SetWinEventHook callback now signals a separate thread, uv__tty_console_resize_watcher_thread. This thread calls uv__tty_console_signal_resize() which checks if the console was actually resized. The uv__tty_console_resize_watcher_thread makes sure to not to call the uv__tty_console_signal_resize function more than 30 times per second. The SetWinEventHook will not be installed, if the PID of the conhost.exe process that owns the console window cannot be determinated. This can happen when a 32bit libuv app is running on a 64bit Windows. For such cases PR libuv#1408 is partially reverted - when tty reads WINDOW_BUFFER_SIZE_EVENT, it will also trigger a call to uv__tty_console_signal_resize(). This will also help when the app is running under console emulators. Documentation was alos updated to reflect that. Refs: microsoft/terminal#1811 Refs: microsoft/terminal#410 Refs: libuv#2308
Continuing improvement of SIGWINCH from PR #2308. Running SetWinEventHook without filtering for the specific PIDs has significant impact on the performance of the entire system. This PR changes the way SIGWINCH is handled. The SetWinEventHook callback now signals a separate thread, uv__tty_console_resize_watcher_thread. This thread calls uv__tty_console_signal_resize() which checks if the console was actually resized. The uv__tty_console_resize_watcher_thread makes sure to not to call the uv__tty_console_signal_resize function more than 30 times per second. The SetWinEventHook will not be installed, if the PID of the conhost.exe process that owns the console window cannot be determinated. This can happen when a 32bit libuv app is running on a 64bit Windows. For such cases PR #1408 is partially reverted - when tty reads WINDOW_BUFFER_SIZE_EVENT, it will also trigger a call to uv__tty_console_signal_resize(). This will also help when the app is running under console emulators. Documentation was also updated to reflect that. Refs: microsoft/terminal#1811 Refs: microsoft/terminal#410 Refs: #2308 PR-URL: #2381 Reviewed-By: Ben Noordhuis <[email protected]>

Add SetWinEventHook for EVENT_CONSOLE_LAYOUT for better detection of
console resize events.
Ref: nodejs/node#13197