fix(network): surface launcher stderr on premature exit in background mode#676
Draft
lwshang wants to merge 3 commits into
Draft
fix(network): surface launcher stderr on premature exit in background mode#676lwshang wants to merge 3 commits into
lwshang wants to merge 3 commits into
Conversation
… mode In background mode the native launcher's stderr is redirected to a log file rather than inherited, so when it exits prematurely (e.g. its fixed gateway port is already taken) the user only saw "exited prematurely with status 101" with no cause. Read the log tail back and fold it into the LauncherExitedPrematurely error (bounded to the last 50 lines / 8 KB, char-boundary safe, fail-soft if the file is unreadable). Foreground is unchanged: its stderr is already inherited and streamed live (#675), so the detail suffix stays empty there. Adds a unix-only integration test that occupies a port with a raw TCP listener (which passes icp-cli's own descriptor-based port check but makes the launcher fail to bind), runs `network start --background`, and asserts the captured output is attached to the error without pinning the exact launcher / pocket-ic wording. Refs #597 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Surfaces captured native launcher errors when background startup fails prematurely.
Changes:
- Appends a bounded stderr tail to premature-exit errors.
- Adds unit and integration coverage for error reporting.
- Cleans up orphaned test processes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
crates/icp/src/network/managed/launcher.rs |
Reads, bounds, and reports launcher stderr. |
crates/icp-cli/tests/network_tests.rs |
Adds port-conflict regression coverage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The test is #[cfg(unix)], but TcpListener was imported at module scope, so on Windows (where the test is compiled out) it was an unused import and failed the build under -D warnings. Move the import into the test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Require the "Launcher error output" header instead of also accepting the empty/unreadable-log fallback, so the integration test fails if the real launcher stderr is never read/wired (the header is our own string, so it still doesn't depend on pocket-ic's wording). - Move the orphaned-pocket-ic cleanup into an RAII guard that reaps on Drop, so it still runs when an assertion panics — the failure path is exactly the one that leaves pocket-ic orphaned. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Follow-up to #675 for issue #597. In background mode the native launcher's stderr is redirected to a log file rather than inherited, so when it exits prematurely (e.g. its fixed gateway port is already in use by Docker) the user only saw:
with no indication of why.
This reads the launcher's captured stderr back and folds the tail into the
LauncherExitedPrematurelyerror, so the cause travels with the error:How
premature_exit_detail(background, stderr_file)inlauncher.rs, called from the premature-exit arm of theselect!:stderr.log, tails it (last 50 lines, then 8 KB, cut on a char boundary), and embeds it. Best-effort: on an unreadable/empty file it falls back to pointing at the log path rather than masking the exit status.detail: Stringfield to the error variant and appends{detail}to the#[snafu(display)].Tests
#[cfg(unix)]integration test that occupies a port with a rawTcpListener(which passes icp-cli's own descriptor-based port check but makes the launcher fail to bind the gateway), runsnetwork start --background, and asserts the captured output is attached to the error without pinning the exact launcher / pocket-ic wording. It also reaps any process spawned under the test's isolated temp home so it doesn't leak an orphaned pocket-ic.Scope / follow-ups
Uses
Refs #597rather thanFixesbecause two related items are intentionally out of scope and are tracked separately:spawn_docker_launcherhas the same class of bug via a separateContainerExitedPrematurelyerror and a different mechanism (needsdocker logs, and can't be covered by this unix/native integration test). → network start: Docker launcher discards container output on premature exit (same as #597 for native) #677🤖 Generated with Claude Code