Fix/windows pty crash#11559
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello @LayorX, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a crucial stability improvement for the CLI on Windows by addressing a persistent crash related to Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request aims to fix a crash on Windows when node-pty fails. The fix involves adding error handling for a race condition where a PTY is resized after it has already exited. While the changes address the crash, there appears to be redundant error handling logic. The error is handled both in the AppContainer.tsx component and within the ShellExecutionService. My review suggests centralizing this logic in the service layer for better code structure and to avoid duplication.
|
Hi @LayorX, thanks for the contribution! Added a couple nits to make sure this has some regression tests. |
| @@ -750,8 +750,14 @@ export class ShellExecutionService { | |||
| } catch (e) { | |||
| // Ignore errors if the pty has already exited, which can happen | |||
| // due to a race condition between the exit event and this call. | |||
| if (e instanceof Error && 'code' in e && e.code === 'ESRCH') { | |||
| // ignore | |||
| if ( | |||
There was a problem hiding this comment.
Nit: could you add a regression test, so if this line is removed it would fail.
There was a problem hiding this comment.
Hi @galz10, thank you for the feedback. I have now added regression tests to cover the fix for the pty resize issue. I'd
appreciate it if you could review the changes again.
| Math.floor(terminalWidth * SHELL_WIDTH_FRACTION), | ||
| Math.max(Math.floor(availableTerminalHeight - SHELL_HEIGHT_PADDING), 1), | ||
| ); | ||
| try { |
There was a problem hiding this comment.
Nit: could you add a regression test, so if this line is removed it would fail.
There was a problem hiding this comment.
Hi @galz10, thank you for the feedback. I have now added regression tests to cover the fix for the pty resize issue. I'd
appreciate it if you could review the changes again.
LayorX
left a comment
There was a problem hiding this comment.
- The test in
AppContainer.test.tsxensures the UI doesn't crash when the resize error is thrown. - The test in
shellExecutionService.test.tsverifies that the service itself handles the error gracefully.
| @@ -750,8 +750,14 @@ export class ShellExecutionService { | |||
| } catch (e) { | |||
| // Ignore errors if the pty has already exited, which can happen | |||
| // due to a race condition between the exit event and this call. | |||
| if (e instanceof Error && 'code' in e && e.code === 'ESRCH') { | |||
| // ignore | |||
| if ( | |||
There was a problem hiding this comment.
Hi @galz10, thank you for the feedback. I have now added regression tests to cover the fix for the pty resize issue. I'd
appreciate it if you could review the changes again.
|
@LayorX it looks like you may have a few conflicts + a few test failures. That being said LOVE the contribution and thank you for thinking of us ❤️ |
|
@NTaylorMullen @galz10
With these changes, all other tests now pass locally. The core fix for the Windows PTY crash is ready for review. Thank you for your |
|
Looks like there is another conflict now. Sorry for the delay here @LayorX |
On Windows, a race condition can occur where a resize event is processed for a pseudo-terminal (pty) that has already exited. This was throwing an unhandled error, 'Cannot resize a pty that has already exited,' causing the entire CLI process to crash. The existing error handling in resizePty only checked for the ESRCH error code, which is specific to Unix-like systems. This change updates the catch block to also identify the Windows-specific error message, allowing the error to be safely ignored in the same way as its Unix counterpart. This improves the stability of shell command execution on Windows, especially for short-lived commands.
This commit introduces a ry...catch block around the ShellExecutionService.resizePty call within AppContainer.tsx. This acts as a safeguard to prevent the UI from crashing if the underlying pty process exits unexpectedly before the resize operation can complete. This change provides an additional layer of resilience and prevents the entire CLI from terminating due to this specific race condition on Windows.
Adds two regression tests to ensure the CLI does not crash when a pty process exits before a resize operation can be performed. This scenario was causing crashes on Windows. - A test in `AppContainer.test.tsx` simulates the error being thrown during a render cycle and asserts that the component does not crash. - A test in `shellExecutionService.test.ts` directly tests the `resizePty` method, ensuring it catches the specific error and does not re-throw it. This addresses the feedback from the pull request review to ensure the fix is robust and prevents future regressions.
6b0728f to
92b3a2f
Compare
|
Hi @galz10 @NTaylorMullen @jackwotherspoon, I have just updated this branch with the latest changes from main to resolve the merge conflicts. This PR should be ready for another look Thank you! |
|
/gemini summary |
Summary of ChangesThis pull request significantly improves the stability of the CLI on Windows by introducing robust error handling for Highlights
Changelog
Activity
|
|
Thanks for this contribution. There was a merge error and tests were still failing so in the interest of time, I made changes and submitted PR #12587. Once that's approved and merged, I will close this one out. |
|
TLDR
I've implemented a fix to prevent the CLI from crashing on Windows when
node-ptyencounters an error. This is a temporary solution.Dive Deeper
I've added a
try...catchblock toAppContainer.tsxto gracefully handle the exception fromshellExecutionService.ts. This prevents the application from crashing whennode-ptyfails on Windows.Reviewer Test Plan
fix/windows-pty-crashbranch.node-ptyerror (if a reliable method is known).packages/cli/src/ui/AppContainer.tsx.Testing Matrix
Linked issues / bugs
Closes #11464
Closes #11502
Closes #11605
Closes #10258
Related to #11552