Skip to content

fix(server): queue follow-up restart if requested during in-flight restart (fix #23392) - #23396

Closed
santusht06 wants to merge 1 commit into
vitejs:mainfrom
santusht06:fix/restart-race-condition-23392
Closed

santusht06 wants to merge 1 commit into
vitejs:mainfrom
santusht06:fix/restart-race-condition-23392

Conversation

@santusht06

Copy link
Copy Markdown

Description

fixes #23392

When a config/env change lands while restartServer is in flight (e.g. fast consecutive edits or switching branches with git checkout), server.restart() returns the active _restartPromise directly without scheduling a follow-up restart once the current one completes. As a result, the server stays running the previous config snapshot.

This PR adds an internal _pendingRestart flag to server.restart() so that if another restart request arrives while a restart is in flight, restartServer loops until no pending requests remain before resolving the promise.

Added a test case in hooks.spec.ts covering concurrent server.restart() calls.

@github-actions github-actions Bot added the bot: likely Likely a bot, LLM, or agent. Automatically comments and closes the issue or PR label Aug 28, 2026
@github-actions

Copy link
Copy Markdown
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.

@github-actions github-actions Bot closed this Aug 28, 2026
@santusht06

Copy link
Copy Markdown
Author

Hi maintainers,

This is a legitimate manual fix. I investigated #23392, reproduced the race condition with the author's reproduction repo (silentoplayz/vite-restart-race-repro), and traced where in-flight restarts drop subsequent requests in packages/vite/src/node/server/index.ts.

The fix uses a _pendingRestart flag in server.restart() to queue and loop through subsequent restarts before settling _restartPromise. I also added a unit test in hooks.spec.ts and verified that all test suites, typechecks, and linters pass.

Please let me know if any changes are needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot: likely Likely a bot, LLM, or agent. Automatically comments and closes the issue or PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vite.config change during an in-flight config restart is silently dropped, leaving the server running a config that no longer matches disk

1 participant