Skip to content

fix(svelte-check): flush stdout/stderr before exit#3014

Merged
jasonlyu123 merged 3 commits intosveltejs:masterfrom
jackgdll:fix/svelte-check-flush-stdout
May 1, 2026
Merged

fix(svelte-check): flush stdout/stderr before exit#3014
jasonlyu123 merged 3 commits intosveltejs:masterfrom
jackgdll:fix/svelte-check-flush-stdout

Conversation

@jackgdll
Copy link
Copy Markdown
Contributor

Resolves: #3013

process.stdout.write is asynchronous on non-TTY pipes, and per Node's docs process.exit does not wait for queued I/O. Under heavy diagnostic load (1000+ ERROR/WARNING lines, enough to saturate the kernel pipe buffer) the trailing COMPLETED summary of --output machine-verbose was dropped when the CLI exited, even though the run was clean.

Replace the bare process.exit(N) calls in both CLI completion paths (default and useVirtualFiles) with the canonical flush-then-exit pattern.

Add a regression test test-flush.js (pnpm run test:flush) that runs the CLI against a fixture emitting 1500 diagnostics, throttles the consumer to keep the pipe full, and asserts the last non-empty line matches ^\d+ COMPLETED across 10 runs. This is useful for testing this fix but I don't know if it's worth actually commiting it to the repo or not.

test-flush.js is AI generated and manually reviewed.

`process.stdout.write` is asynchronous on non-TTY pipes, and per Node's docs `process.exit` does not wait for queued I/O. Under heavy diagnostic load (1000+ ERROR/WARNING lines, enough to saturate the kernel pipe buffer) the trailing `COMPLETED` summary of `--output machine-verbose` was dropped when the CLI exited, even though the run was clean.

Replace the bare `process.exit(N)` calls in both CLI completion paths (default and `useVirtualFiles`) with the canonical flush-then-exit pattern.

Add a regression test `test-flush.js` (`pnpm run test:flush`) that runs the CLI against a fixture emitting 1500 diagnostics, throttles the consumer to keep the pipe full, and asserts the last non-empty line matches `^\d+ COMPLETED` across 10 runs.
This is useful for testing this fix but I don't know if it's worth actually commiting it to the repo or not.
`test-flush.js` is AI generated and manually reviewed.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 30, 2026

🦋 Changeset detected

Latest commit: 4d40adb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte-check Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jackgdll jackgdll closed this Apr 30, 2026
@jackgdll jackgdll reopened this Apr 30, 2026
@jasonlyu123
Copy link
Copy Markdown
Member

Thanks you. I removed the test from the build script since it already serves the verification purpose, and it's unlikely to break in the future. Still keeping the test file so we can run it manually.

@jasonlyu123 jasonlyu123 merged commit 35428ae into sveltejs:master May 1, 2026
3 checks passed
@github-actions github-actions Bot mentioned this pull request May 1, 2026
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.

svelte-check exits before writing the full output to pipe when there are a large number of diagnostics

2 participants