fix(eval): vite-node-specific defense against the server-close race that throws ERR_CLOSED_SERVER#203
Open
Hiroki Osame (privatenumber) wants to merge 6 commits into
Conversation
…portingTsExtensions
…/promises in fixture
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.
Problem
bt eval --runner vite-node <file>.tsfails witherror: eval runner exited with status exit status: 1for projects whose Vite config enablesdev.recoverablefor SSR (Vite wrappers like vite-plus do by default). Invoking the cached eval-runner directly surfaces the real error:ERR_CLOSED_SERVERfrom vite'stransformRequest.vite-node's CLI does
await runner.executeFile(file); await server.close();(cli.ts:146-152).executeFileresolves the moment vite-node's async wrapper around the entry returns, which is immediately if the entry uses fire-and-forget. The eval-runner usedmain().catch(...)at the top level, so vite-node tore down the dev server whilemain()was still resolvingawait import()calls.Same bug class as vitejs/vite#13786. The pattern has been latent since vite-node support landed; it surfaces now because configs that re-enable
dev.recoverablereopen the closed-server guard that #13787 silenced for SSR by default.tests/evals/js/eval-vite-node-server-close-race/reproduces it deterministically.Changes
Only vite-node's CLI needs top-level await; every other runner (tsx, bun, deno, ts-node, plain Node) has event-loop semantics where fire-and-forget is the natural pattern. The runner is split to reflect that:
scripts/eval-runner-impl.ts— shared impl. Exportsmain().scripts/eval-runner.mts— vite-node entry: importsmainandawaits it..mtsforces ESM at the loader for tsx/Bun/Deno; vite-node is format-agnostic..tsentry generated byjs_runner_default_source(): impl body withmain().catch(...)appended. Standalone (no import) to avoid a Deno-vs-ts-node.ts-extension conflict.src/eval.rs—js_runner_path_for_kindswaps the runner script to.mtsonly forRunnerKind::ViteNode.