Skip to content

fix(core): prevent hanging between command end and process exit#33500

Merged
FrozenPandaz merged 1 commit intomasterfrom
fix/process-exit-hanging-2
Nov 17, 2025
Merged

fix(core): prevent hanging between command end and process exit#33500
FrozenPandaz merged 1 commit intomasterfrom
fix/process-exit-hanging-2

Conversation

@AgentEnder
Copy link
Copy Markdown
Member

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.

@AgentEnder AgentEnder requested a review from a team as a code owner November 15, 2025 04:07
@vercel
Copy link
Copy Markdown

vercel bot commented Nov 15, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
nx-dev Ready Ready Preview Nov 15, 2025 4:13am

@netlify
Copy link
Copy Markdown

netlify bot commented Nov 15, 2025

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit 7eb8ad8
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/6917fc78162236000831e193
😎 Deploy Preview https://deploy-preview-33500--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud bot commented Nov 15, 2025

View your CI Pipeline Execution ↗ for commit 7eb8ad8

Command Status Duration Result
nx affected --targets=lint,test,test-kt,build,e... ✅ Succeeded 13m 19s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 2m 47s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 11s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 3s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 1s View ↗

☁️ Nx Cloud last updated this comment at 2025-11-15 15:16:28 UTC

Comment on lines +13 to +16
if (
chunk.codePointAt(chunk.length - 1) === VERY_END_CODE &&
message.endsWith(MESSAGE_END_SEQ)
) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Simply use if (message.endsWith(MESSAGE_END_SEQ)) which already handles the complete check
  2. 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.

Suggested change
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

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@FrozenPandaz FrozenPandaz merged commit d86fb5d into master Nov 17, 2025
21 of 22 checks passed
@FrozenPandaz FrozenPandaz deleted the fix/process-exit-hanging-2 branch November 17, 2025 14:57
FrozenPandaz pushed a commit that referenced this pull request Nov 17, 2025
## 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)
@github-actions
Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants