Repository navigation
Conversation
`vite build --watch` died from SIGINT/SIGTERM without closing its watchers, so plugin `closeWatcher` hooks never ran: a plugin that cleans up in `closeWatcher` (temp files, child processes) leaked on every interrupted watch build (TanStack Start left 330 temp directories on one machine). `rollup -w`, `rolldown -w` and `vite dev` close on both signals. When the watch watcher is created, listen for SIGINT/SIGTERM: close the watcher (running `closeWatcher` hooks), then exit with the conventional code (130/143). The command lock's handlers release the lock and re-raise the signal; these consume the re-raised signal while the watcher closes, guarded against double invocation. Fixes vitejs#24181
Contributor
|
This PR has been automatically flagged as likely to be created by a bot, LLM, or agent, and will be automatically closed. These contributions harm the maintenance of the project. Please read our AI policy for more information. If you believe this is a mistake, please reply to this comment and we will review it. |
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.
Fixes #24181.
The bug
vite build --watchdied from SIGINT/SIGTERM without closing its watchers, so plugincloseWatcherhooks never ran: a plugin that cleans up incloseWatcher(temp files, child processes) leaked on every interrupted watch build — TanStack Start left one temp directory per interrupted build (330 on one machine).rollup -w,rolldown -wandvite devall close on both signals;setupSIGTERMListeneris registered by the dev and preview servers only.The fix
When the watch watcher is created in
buildEnv, listen for SIGINT/SIGTERM: close the watcher (runningcloseWatcherhooks), then exit with the conventional code (130 for SIGINT, 143 for SIGTERM, matchingcommandLock.ts's convention).Interaction with the command lock (registered earlier by the CLI's build action): its handlers release the lock and re-raise the signal; these
process.onhandlers consume the re-raised signal while the watcher closes (aclosingguard prevents double invocation), then exit explicitly — relying on a default death there would cut the close short. Without the lock (--bypassLock) the same handlers run on the original signal.Verified (built from source, real
vite build --watchwith the issue's log-hooks plugin)Baseline rebuilt from stashed main reproduced the bug (no
closeWatcheron SIGTERM); rebuilding with the fix shows it on both signals.