Repository navigation
fix: keep the Bun dev server correct and flat across hot reloads - #1584
Merged
Merged
Conversation
|
Preview for Next: fix the listed keys in the compose file |
Under bun --hot every edit re-ran the whole dev server without disposing the previous one: memory grew ~25 MB an edit until bun --hot stopped reloading, instrumentation ran again per edit, and a new instance built its route table before its watchers existed, so files changed while it booted were never seen (404s for routes that exist, unknown actions). Bun also kept the old source of a replaced file forever, a stale directory listing for new files next to server modules, and hung on re-importing a module that failed to parse; a server-module edit restarted the process, dropping requests for up to 2 s. The first run now owns the process and a re-run only resets the module registry; app modules load through a fresh-reading plugin, # aliases resolve through the app's map, the watcher pokes a sentinel instead of restarting, dev re-imports are keyed by content (no per-request module leak), and the analysis caches survive rebuilds. A stress script that edits like an AI agent runs on both runtimes. Closes #1575 Claude-Session: https://claude.ai/code/session_01SZ72LSPAo4NvYvBDSD6RLo
vivek7405
force-pushed
the
fix/bun-dev-hot-reload
branch
from
October 7, 2026 12:19
22e2eee to
771afcc
Compare
This was referenced Oct 7, 2026
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.
Closes #1575
Found by a stress script that edits a running
webjs devapp the way an AI agent does (bursts, partial writes, syntax errors then fixes, renames, deletes, atomic writes, a whole feature at once, checkout-like churn), against a freshbun create webjs --db postgresapp and Crisp's app.Root causes (Bun,
bun --hot)startServerran again: a second handler, watchers, SSE hub, process handlers,instrumentation.register()andBun.plugins, none disposed. ~25 MB per edit (153 MB to 5.8 GB over 225 edits), after whichbun --hotstopped reloading and component edits were never served.#import of a new file next to*.server.*modules, and hangs on re-importing a module that failed to parse.*.server.*edit restarted the process (connection refused for 0.3 to 2 s); every dev re-import used a random query, leaking a module instance per request (~60 KB).Fix
dev/hot-host.js: the first run owns the process; a re-run (CLI fast pathlib/dev-hot-rerun.js) only resets the registry and re-derives the analysis. Framework upgrade mid-session exits the child for the supervisor to restart.dev/bun-app-source.js),#aliases resolve through the app map (dev/bun-alias-resolve.js); the watcher pokes a temp-dir sentinel for a registry reset when needed, instead of restarting. The supervisor narrows restarts toinstrumentation.*/env.*once the child announces in-place reload over IPC.devImport: content-keyed specifiers, never re-importing a failed one.Results (stress script, 43 checks)
bun test/bun/dev-reload-stress.mjsagainst main's server/cli: 4 fail.Tests
npm testgreen (4973 pass); Bun matrix: alltest/bun/dev-*.mjsgreen under Bun; newtest/bun/dev-reload-stress.mjs(both runtimes),packages/server/test/dev/hot-reload-robustness.test.js, supervisor tests.https://claude.ai/code/session_01SZ72LSPAo4NvYvBDSD6RLo