Skip to content

fix: improve telemetry worker stderr cleanup#3648

Merged
eablack merged 2 commits intomainfrom
eb/improve-telemetry-worker-exit-logic
Apr 7, 2026
Merged

fix: improve telemetry worker stderr cleanup#3648
eablack merged 2 commits intomainfrom
eb/improve-telemetry-worker-exit-logic

Conversation

@eablack
Copy link
Copy Markdown
Contributor

@eablack eablack commented Apr 6, 2026

Summary

Improved the telemetry worker's exit logic to properly flush stderr before exiting. The previous implementation used setImmediate() + process.stderr.destroy(), which did not guarantee that buffered writes were flushed, potentially causing debug messages to be lost and the parent process to hang when stderr is inherited in DEBUG mode.

The new implementation:

  • Uses process.stderr.end() with a callback to ensure all buffered data is flushed before exit
  • Adds a fallback setImmediate() in a finally block to prevent the worker from hanging if end() fails
  • Properly releases the inherited stderr file descriptor, preventing the parent process from being blocked

Type of Change

Patch Updates (patch semver update)

  • fix: Bug fix

Testing

Notes:
This change affects the telemetry worker process that runs in the background when DEBUG mode is enabled. The issue would manifest as the parent CLI process hanging or debug messages being truncated.

Steps:

  1. Run CLI commands with DEBUG=heroku:analytics to verify telemetry worker exits cleanly
  2. Verify debug messages are not truncated in stderr output
  3. Confirm parent process does not hang waiting for worker to exit
  4. Passing CI suffices for regression testing

Replace setImmediate + destroy() with process.stderr.end() callback
to ensure all buffered writes are flushed before exiting. Add fallback
exit in finally block to prevent worker from hanging if end() fails.

This properly releases the inherited stderr file descriptor in debug
mode, preventing the parent process from being blocked.
@eablack eablack requested a review from a team as a code owner April 6, 2026 22:33
@eablack eablack temporarily deployed to AcceptanceTests April 6, 2026 22:34 — with GitHub Actions Inactive
@eablack eablack temporarily deployed to AcceptanceTests April 6, 2026 22:34 — with GitHub Actions Inactive
@eablack eablack temporarily deployed to AcceptanceTests April 6, 2026 22:34 — with GitHub Actions Inactive
@eablack eablack temporarily deployed to AcceptanceTests April 6, 2026 22:34 — with GitHub Actions Inactive
@eablack eablack changed the title fix: improve telemetry worker stderr cleanup to prevent hanging fix: improve telemetry worker stderr cleanup Apr 7, 2026
Only call process.stderr.end() when DEBUG env var is set, mirroring the
parent process logic where stderr is inherited only in DEBUG mode. When
stderr is ignored, closing it is unnecessary and could cause issues.
@eablack eablack temporarily deployed to AcceptanceTests April 7, 2026 00:15 — with GitHub Actions Inactive
@eablack eablack temporarily deployed to AcceptanceTests April 7, 2026 00:15 — with GitHub Actions Inactive
@eablack eablack temporarily deployed to AcceptanceTests April 7, 2026 00:15 — with GitHub Actions Inactive
@eablack eablack temporarily deployed to AcceptanceTests April 7, 2026 00:15 — with GitHub Actions Inactive
Copy link
Copy Markdown
Contributor

@k80bowman k80bowman left a comment

Choose a reason for hiding this comment

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

Thanks for continuing to iterate on this!

@eablack eablack merged commit 150e74a into main Apr 7, 2026
31 of 32 checks passed
@eablack eablack deleted the eb/improve-telemetry-worker-exit-logic branch April 7, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants