Repository navigation
Conversation
The two tests save main.js in place. fs.writeFileSync writes over the file and then resizes it, which is two watcher events. When --hot reloads between them, the second load runs twice and prints "collected" twice, or the third load parses the new file followed by the tail of the old one. The three saves now have the same length and differ in one digit, so a read always gets one whole version. The second load does its work once. The 20,000 promises are made before the first catch(), so the collected cell goes to one of them and not to a promise that catch() returns.
|
No actionable comments were generated in the recent review. WalkthroughThe hot-reload test documents that one save can trigger two loads. Its second-load script logs ChangesHot reload promise reuse
Suggested reviewers: Merge Risk:
|
|
Status: ready for review. This PR changes tests only: 4 added lines and 1 removed line. CI (build 141369, this head): How the failure was reproduced: a probe did the syscalls of
The flake on main: Not in this PR: the |
main pads the third save of the entry-point promise tests to the length of the second, so a load between the write and the resize no longer reads the tail of the second text. This branch keeps that and drops its own way to the same end (three saves that differ in one digit). What stays from this branch: the second load does its work once, since one save can reload twice, and the 20,000 promises are made before the first catch().
|
Updated 12:29 AM PT - Nov 14th, 2026
✅ @robobun, your commit a69dadb9d6ce31243944ccd3c421d2c903efe085 passed in 🧪 To try this PR locally: bunx bun-pr 44666That installs a local version of the PR into your bun-44666 --bun |
There was a problem hiding this comment.
LGTM — after the merge of main the change is down to two test-only edits in test/cli/hot/hot.test.ts (the if (!globalThis.kept) guard and making the 20,000 promises before the first catch()), both of which read as correct.
What was reviewed:
- Checked whether the guard lets an unfixed build pass when one save reloads twice: the gc/readFile/setImmediate/randomBytes chain still runs once and the current entry-point promise is collected the same way, so the property from #44350 is still asserted. I did not run the unfixed-build check the PR describes.
- Verified both new comments against source:
writeFileSyncopens withoutO_TRUNCand callsftruncateafter the write (src/runtime/node/node_fs.rs:8278-8387), andcatch()on a rejected promise yields a fulfilled one. The secondforloop attaches every handler synchronously, so no unhandled rejection fires before it. - Note: the PR description still describes the "three saves differ in one digit"
source(1|2|3)shape from the first commit; after the merge, the test keeps main'spadEndthird write instead, so the description is stale.
Extended reasoning...
The diff touches one test file only (test/cli/hot/hot.test.ts, lines 912-931) and no production code, so it has no security-sensitive surface. The original commit rewrote the three saves as one source(load) template, but the merge of main dropped that in favor of main's existing padEnd approach, leaving just the reload guard and the push-then-catch split. The guard removes the double "collected" from a double watcher event without changing the GC stack depth or count, and the catch split strengthens the test by keeping catch-derived fulfilled promises from taking the collected cell. The bug hunt ran dry, the single candidate (guard weakening the test) was ruled out by reading, and no CODEOWNER covers the path, which decided approve.
|
On the stale description: it was rewritten after the merge with |
The merge commit skipped the work of a second load of the second text. Every load now does the work again, as on main. Only the line is printed once, so a save that reloads twice no longer fails the test.
There was a problem hiding this comment.
Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.
Beyond the inline nit, I also checked the two new comment claims against source: a path-based writeFileSync does write and then ftruncate (src/runtime/node/node_fs.rs:8352-8388), and the 20000 .catch() handlers are all attached synchronously before any microtask checkpoint, so the "rejected and handled" case still raises no unhandled rejection. Not run here: that the reordered test still fails on a build without the #44350 fix; the PR's own-build numbers are the only evidence of that.
Extended reasoning...
The change is one hunk in test/cli/hot/hot.test.ts: the second-load source now creates all promises before attaching any catch handler and prints "collected" only once per --hot session via a globalThis guard; the exact stdout/stderr assertion is unchanged. No production code and no security-sensitive surface is touched. Reading confirmed both new comments are true, but whether the test still catches the original use-after-free is an empirical property of heap cell reuse that reading cannot settle, so this is a note of what was ruled out rather than an approval.
Additional findings (outside the current diff — GitHub can't attach inline comments there):
-
🟣
test/cli/hot/hot.test.ts— nit, pre-existing: a maintainer gets a passing run even if the third load exits non-zero, since the test never asserts the exit code. The finaltoEqualat test/cli/hot/hot.test.ts:937 checks only{ stdout, stderr };runner.exitedis never awaited, although the third text callsprocess.exit(0). Fix: awaitrunner.exitedtogether withrunner.stderr.text()and assert a combined{ stdout, stderr, exitCode: 0 }object, so a reload that prints "third load" but exits with another code (or is killed on dispose) fails the test.Why this was flagged
The third text written at test/cli/hot/hot.test.ts:934 is
console.log("third load"); process.exit(0);. Afterawait line("third load")at line 935 the test readsrunner.stderr.text()at line 936 and asserts only{ stdout, stderr }at lines 937-940.runner.exitedis never awaited and no exit code is asserted, so a run in which bun prints "third load" and then exits non-zero without writing to stderr (an exit-path regression under --hot) still passes. The base branch has the same gap; this PR edits the same test body (lines 920-926) without adding the exit-code assertion that REVIEW.md asks of subprocess tests.Verification: pre-existing (nit). Triggering condition: a --hot run that prints "third load" and then exits with a non-zero code without writing anything to stderr. Nothing in test/cli/hot/hot.test.ts:934-940 references
runner.exitedorexitCode. So the exit status of the third load is never observed. The same lines are byte-identical in the base commit 4bf0ef9, so the gap predates this PR.
There was a problem hiding this comment.
LGTM — a small, test-only change that keeps the original property under test while tolerating the two watcher events one writeFileSync produces.
What was reviewed:
- The
globalThis.collectedguard: the first load of the second text always prints (the flag is unset), a repeat load still does the GC and 20000-promise work and only skips the print, andglobalThis.keptis reset per load, so no path leavescollectedunprinted or printed twice. - The two-pass loop: all
.catch()calls still run synchronously in the same callback before any microtask checkpoint, so no unhandled rejection reaches stderr; the reordering changes allocation order, not GC depth or count. - The new
expect(await runner.exited).toBe(0)sits after the stdout/stderr assertion and the third text callsprocess.exit(0), so it cannot hang; ordering matches the harness convention. - Not done here: I did not run the test, nor verify the PR's claim that the reordered loop fails the
rejected and handledcase on a build from before #44350.
Extended reasoning...
The diff touches one test file, test/cli/hot/hot.test.ts, in a single it.each case for --hot entry-point promise reuse: it splits promise creation from .catch() attachment, guards the collected print with a global flag so a double reload prints once, and adds a trailing exit-code assertion. It touches no production code and no security-sensitive surface. No CODEOWNERS entry covers this path, the timeline shows no CHANGES_REQUESTED state or unaddressed objection, and the hunt ran dry; the change is small enough to verify fully by reading, which decided approve over defer.
The second text makes its promises in the order that main has again, and the note on the two watcher events moves out of the text. What stays: "collected" is printed once, and the exit code is checked. With the promises made before the first catch(), the "pending" case timed out on windows 11 aarch64 in both CI runs of this branch (builds 141268 and 141322) and passed on the retry. The cause is not known.
Problem
does not take a promise of the program's, %s, for that of the entry pointfails an attempt in 52 of 455 CI builds (Nov 11 to 13), on the Linux release lanes: stdout is["first load", "collected", "collected", "third load", ""].main.jsin place.fs.writeFileSyncwrites over the file, then callsftruncate(src/runtime/node/node_fs.rs:8278): two watcher events. A reload between them runs the second load twice.Fix
collectedonce. Each load still does the work, as onmain.bun bd test test/cli/hot/hot.test.tspasses. With 5 ms between the two calls, the tests ofmainfail 8 of 8 and these pass 8 of 8.Background
bun --hotruns the entry point again when a watched file changes. The watcher waits 100 µs for more events (src/watcher/INotifyWatcher.rs:70). A later event is a second reload (Duplicate Output Issue After Repeated Saves withbun --hot#13511).--hotread the entry point's promise after its collection.main, so a load between the two calls no longer reads the tail of the second text.writeHotFileAtomicSync): also two events, and on Windows the helper removes the file first.rejected and handledcase does not catch the bug of --hot: fix a use-after-free of the entry point's promise #44350. A change for that timed out on Windows in CI (Notes).Notes
This PR changes tests only. No file under
src/changes. The diff againstmainis 4 added lines and 1 removed line in one test.Source of the CI numbers. Annotations of the 455 finished builds 140029 to 141204 (2026-11-11 to 2026-11-13). The two tests fail an attempt in 59 of them. Every hit passed on the retry.
"collected"twiceExpected ";" but found ")"All 8 builds with the parse error ran a test text without the padding of #48677. With the padding it does not occur.
"collected"twice occurs with the padding too, in 11 builds: 140753, 140778, 140788, 140919, 140935, 140977, 141013, 141046, 141083, 141109, 141176.The doubled load from a delay between the two calls. A probe does the syscalls of
fs.writeFileSyncby hand (openSyncwithoutO_TRUNC,writeSync, a busy wait,ftruncateSync) for the two saves. Debug build of this branch, 8 tests per cell (4 runs of the 2 cases):mainfailsEvery failure is
"collected"twice, the same diff as in CI. Theftruncateis an event of its own even when it does not change the size. The text of this PR also passes with delays from 20 ms to 1.5 s, which put the second load at each step of the first (16 tests), and with three events for each save (8 tests).Without the probe. The two tests next to 24 busy loops on 12 cores, debug build: the text of
mainfails 1 of 104 test runs ("collected"twice), the text of this PR fails 0 of 72. CI has about the same rate formain: 55 job hits in 455 builds, with 6 Linux release lanes and 2 cases for each build.Why the line is printed once.
--hotcan reload twice for one save, and this test is not about that. The older tests in this file accept it too (expect(reloadCounter).toBeGreaterThanOrEqual(3), anddriveErrorReloadCyclesaves again when it sees the previous error). #30617 (open) makes the watcher wait longer before it posts a reload. This PR does not depend on it. Every load still does the collections and makes the promises, so the program differs from the one onmainonly in the line it prints.Why a rename does not remove the second reload. A rename over the entry point gives a
MOVED_TOevent on the directory and aDELETE_SELFevent on the replaced file.src/jsc/hot_reloader.rs:1039handles the case that they land in separate reads, and each posts a reload.Not in this PR: the
rejected and handledcase does not catch its bug.Promise.reject(e).catch(() => {})makes two promises: the rejected one and the one thatcatch()returns, which is fulfilled a moment later. The loop makes them in turn, so the collected cell goes to either kind. A fulfilled promise in that cell looks like an entry point that loaded, and the unfixed build passes. Release build from before #44350 (367d939), the real test files:pendingfailsrejected and handledfailsmainand in this PR (promise,catch(), promise,catch())catch()callsTwo earlier commits of this PR had the second loop. With it, the
pendingcase timed out after 90 s on windows 11 aarch64 in both CI runs (builds 141268 and 141322), on the first attempt, and passed on the retry. Therejected and handledcase passed there, and so did windows 2019 x64. No other build from 2026-11-10 to 2026-11-14 has that timeout for these tests (about 600 builds). The second text of those commits also had comments in it: 820 and 826 bytes for thependingcase, against 494 onmainand 562 now. I cannot run Windows and I did not find the cause, so the loop is back to the one onmainand the comments are out of the text. Someone with a windows 11 aarch64 machine can tell which of the two it was. With the loop ofmainand the short text (this head), both Windows lanes passed the file on the first attempt in build 141369.History of this PR. October: the three saves differed in one digit, so that no read could see a mix of two of them.
mainthen padded the third save (#48677), and the merge on 2026-11-13 dropped the digit. The merge commit skipped the work of a second load (if (!globalThis.kept)). That became the printed-once line on 2026-11-14, so that every load does what it does onmain.Other runs. The whole file on the debug build: 26 pass, 2 skip (Windows only), 1 todo, 0 fail. A review note asked for the exit code check. It has the form that the other
--hottests of this file use.Earlier numbers. From 2026-10-02 to 2026-10-06 the two tests failed on Linux in 75 of 400 builds (47 with
"collected"twice, 30 with the parse error). From 2026-10-07 to 2026-10-16 a sample had 3 of 147.Not changed.
holds the promise of the entry point itself, which it looks at on every tickalso saves in place. It waits only for the line of the second load, and it has no failure in the 455 builds.--hot does not emit beforeExit to the listeners of a failed runtimed out on windows 11 aarch64 in 2 of the builds (140982, 141150). That is another test and another failure.no test proof · iteration 2 · platform-specific test(s) that do not run on this machine, deferring to CI, which covers all platforms: test/cli/hot/hot.test.ts