fix(core): prevent hanging between command end and process exit#33500
fix(core): prevent hanging between command end and process exit#33500FrozenPandaz merged 1 commit intomasterfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
✅ Deploy Preview for nx-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
View your CI Pipeline Execution ↗ for commit 7eb8ad8
☁️ Nx Cloud last updated this comment at |
| if ( | ||
| chunk.codePointAt(chunk.length - 1) === VERY_END_CODE && | ||
| message.endsWith(MESSAGE_END_SEQ) | ||
| ) { |
There was a problem hiding this comment.
The current condition may not correctly detect message endings in all cases. The check chunk.codePointAt(chunk.length - 1) === VERY_END_CODE only examines the last character of the current chunk, but the EOT character could have arrived in a previous chunk with the rest of the MESSAGE_END_SEQ arriving in the current chunk.
Consider one of these alternatives:
- Simply use
if (message.endsWith(MESSAGE_END_SEQ))which already handles the complete check - If the preliminary character check is intended as an optimization, use
if (message.charAt(message.length - 1).codePointAt(0) === VERY_END_CODE && message.endsWith(MESSAGE_END_SEQ))
This ensures the message ending is detected correctly regardless of how the data is chunked during transmission.
| if ( | |
| chunk.codePointAt(chunk.length - 1) === VERY_END_CODE && | |
| message.endsWith(MESSAGE_END_SEQ) | |
| ) { | |
| if ( | |
| message.charAt(message.length - 1).codePointAt(0) === VERY_END_CODE && | |
| message.endsWith(MESSAGE_END_SEQ) | |
| ) { |
Spotted by Graphite Agent
Is this helpful? React 👍 or 👎 to let us know.
## Current Behavior In certain scenarios, Nx commands would hang between command completion and process exit. This was caused by inefficient message end detection in the daemon socket communication, where the check for `MESSAGE_END_SEQ` could fail when TCP packets were fragmented. ## Expected Behavior With this PR, the message end detection is more robust and handles TCP packet fragmentation correctly, preventing the hanging issue. The changes also add better performance tracking and logging to help diagnose similar issues in the future. ## Changes Made - **Improved message end detection** (`consume-messages-from-socket.ts`): Added a preliminary check of the last character's code point before checking the full MESSAGE_END_SEQ, which prevents false negatives when TCP packets are fragmented - **Enhanced performance tracking** (`daemon/client/client.ts`, `daemon-socket-messenger.ts`): Added message-type-specific performance marks and measures for better debugging - **Added server-side logging** (`daemon/server/server.ts`): Added logging for message receipt, serialization, and response to help diagnose communication issues ## Related Issue(s) This fix addresses hanging issues observed in daemon communication when commands complete but the process doesn't exit. (cherry picked from commit d86fb5d)
|
This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request. |
Current Behavior
In certain scenarios, Nx commands would hang between command completion and process exit. This was caused by inefficient message end detection in the
daemon socket communication, where the check for
MESSAGE_END_SEQcould fail when TCP packets were fragmented.Expected Behavior
With this PR, the message end detection is more robust and handles TCP packet fragmentation correctly, preventing the hanging issue. The changes also
add better performance tracking and logging to help diagnose similar issues in the future.
Changes Made
consume-messages-from-socket.ts): Added a preliminary check of the last character's code point before checkingthe full MESSAGE_END_SEQ, which prevents false negatives when TCP packets are fragmented
daemon/client/client.ts,daemon-socket-messenger.ts): Added message-type-specific performance marks andmeasures for better debugging
daemon/server/server.ts): Added logging for message receipt, serialization, and response to help diagnosecommunication issues
Related Issue(s)
This fix addresses hanging issues observed in daemon communication when commands complete but the process doesn't exit.