Repository navigation
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughReplaced ref-count-based scaling in BlockList.estimatedSize() with a direct size + estimated_size load; added a GC stability test that repeatedly creates BlockList instances, adds an address, then forces garbage collection to ensure no crash. Changes
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@test/js/node/net/blocklist-gc.test.ts`:
- Around line 1-4: The test currently uses an inline require("net") inside the
test body; replace this with a module-scope import so the test follows the
guideline to avoid dynamic require. Add a top-level import for the Node net
module (e.g., import * as net from "net" or equivalent) and remove the inline
const net = require("net") from the "BlockList does not crash during GC" test so
the test uses the module-scope symbol net.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 5404a367-1afd-4247-a497-c7cb834b33f6
📥 Commits
Reviewing files that changed from the base of the PR and between db2156e and 8d012314b1a1dd6c54c9cde84b15a73bd83abd19.
📒 Files selected for processing (3)
src/bun.js/node/net/BlockList.zigtest/js/bun/s3/s3-fd-validation.test.tstest/js/node/net/blocklist-gc.test.ts
There was a problem hiding this comment.
LGTM — the fix is obviously correct and the inline comment covers the minor test style nit.
Extended reasoning...
Overview
This PR modifies two files: src/bun.js/node/net/BlockList.zig (one-line fix to estimatedSize) and adds a new regression test test/js/node/net/blocklist-gc.test.ts.
Security Risks
None. This is a crash fix in a memory-estimation helper; no auth, crypto, or permission logic is involved.
Level of Scrutiny
Low. The change is a single-line removal of an erroneous division. estimatedSize is meant to report the object's memory footprint to the GC — dividing by ref_count was semantically wrong regardless of the crash, since memory size does not scale inversely with reference count. The fix aligns with every other estimatedSize implementation in the codebase.
Other Factors
The only issue flagged is a minor test style nit (require() inside the test body instead of a module-level import), which is already posted as an inline comment. It does not affect correctness or the regression coverage. The core fix is safe to land.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@test/js/node/net/blocklist-gc.test.ts`:
- Line 5: The test contains inline bug-context comments inside the test body
(e.g., the comment "// Create and discard BlockList instances to trigger GC
collection") which should be removed; open the test file and delete that comment
(and any other inline PR/bug-context comments in the same test body or around
the BlockList usage), leaving only the test setup/action/assertion code that
references the BlockList constructor/instances and related test names so the
test stays focused and readable.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 1140a120-57cf-44ed-90e3-59550f9a31a1
📥 Commits
Reviewing files that changed from the base of the PR and between 8d012314b1a1dd6c54c9cde84b15a73bd83abd19 and 24355254dc7ed1d3a754594b13629ea4f0240482.
📒 Files selected for processing (1)
test/js/node/net/blocklist-gc.test.ts
| import { BlockList } from "node:net"; | ||
|
|
||
| test("BlockList does not crash during GC", () => { | ||
| // Create and discard BlockList instances to trigger GC collection |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
Remove inline bug-context comments from the test body.
These comments restate PR/bug context and should be dropped to keep the test focused on setup/action/assertion.
♻️ Suggested cleanup
test("BlockList does not crash during GC", () => {
- // Create and discard BlockList instances to trigger GC collection
for (let i = 0; i < 10; i++) {
const bl = new BlockList();
bl.addAddress("1.2.3.4");
}
Bun.gc(true);
- // If we get here without SIGFPE, the bug is fixed
expect(true).toBe(true);
});Based on learnings: In test/js/node/** regression/unit tests, avoid inline comments in test bodies that restate bug context or PR references.
Also applies to: 11-11
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@test/js/node/net/blocklist-gc.test.ts` at line 5, The test contains inline
bug-context comments inside the test body (e.g., the comment "// Create and
discard BlockList instances to trigger GC collection") which should be removed;
open the test file and delete that comment (and any other inline PR/bug-context
comments in the same test body or around the BlockList usage), leaving only the
test setup/action/assertion code that references the BlockList
constructor/instances and related test names so the test stays focused and
readable.
There was a problem hiding this comment.
LGTM — the one-line fix correctly removes the division by ref_count.get() from estimatedSize, and the require() nit was addressed in the follow-up commit.
Extended reasoning...
Overview
This PR touches three files: src/bun.js/node/net/BlockList.zig (one-line crash fix), test/js/node/net/blocklist-gc.test.ts (new GC regression test), and test/js/bun/s3/s3-fd-validation.test.ts (trivial import reorder).
Core fix correctness
The removed division / this.ref_count.get() was logically incorrect: estimatedSize is supposed to return the total memory footprint of the object, which does not change based on how many references exist. Dividing by a ref_count that can race to zero on another thread causes SIGFPE (integer divide-by-zero on x86-64). The fix is minimal and clearly correct. No other estimatedSize implementation in the codebase uses this pattern.
Security risks
None. This is a crash fix in a non-security-critical memory-estimation callback used by the JSC GC.
Level of scrutiny
Low. The change is a single-line deletion of a logically incorrect operation. The fix is self-evidently correct from reading the code and the description.
Other factors
The require() inside the test body was flagged by both CodeRabbit and my prior inline comment; it was addressed in commit 2435525. The remaining expect(true).toBe(true) tautology I noted is a nit — it does not affect crash detection correctness (a SIGFPE kills the process before that line is reached). The S3 test import reorder is noise-free. No blocking issues remain.
There was a problem hiding this comment.
LGTM — prior feedback addressed, fix is correct.
Extended reasoning...
Overview
This PR modifies one line in src/bun.js/node/net/BlockList.zig (removing a division by ref_count.get() from estimatedSize) and adds a new GC regression test test/js/node/net/blocklist-gc.test.ts.
Security risks
None. estimatedSize is a GC memory-accounting hint with no security surface. The change cannot introduce injection, auth bypass, or data exposure.
Level of scrutiny
Low. This is a single arithmetic expression change fixing a divide-by-zero crash. No other estimatedSize in the codebase divides by ref_count, confirming this was an anomaly. The fix aligns with established patterns.
Other factors
My two prior review comments — the inline require("net") violation and the tautological expect(true).toBe(true) assertion — were both addressed (commits 2435525 and a0034b4). The final test uses a module-scope import and no superfluous assertion. The only remaining finding (GC double-counting after structured clone) is a nit-level heuristic concern that does not affect correctness or stability.
| pub fn estimatedSize(this: *@This()) usize { | ||
| return (@sizeOf(@This()) + this.estimated_size.load(.seq_cst)) / this.ref_count.get(); | ||
| return @sizeOf(@This()) + this.estimated_size.load(.seq_cst); | ||
| } |
There was a problem hiding this comment.
🟡 After this fix, estimatedSize() reports the full sizeof + estimated_size per JS wrapper, so when a BlockList is shared via structured clone both wrappers independently report the full size, causing the GC to over-estimate heap pressure by 2x (or Nx for N references). The codebase already has a clean precedent for this in Blob Store using hasOneRef() to avoid double-counting, which would handle both the SIGFPE and this issue.
Extended reasoning...
What the bug is: estimatedSize() now returns @sizeof(@this()) + estimated_size unconditionally. When a BlockList is transferred via structured clone, onStructuredCloneSerialize calls this.ref() (incrementing ref_count to 2) and writes the raw native pointer. onStructuredCloneDeserialize restores that same pointer as a second JS wrapper via this.toJS(globalThis). Both JS wrappers now point to the same native BlockList instance.
The specific code path: The GC calls estimatedSize() on each live JS object. With two wrappers sharing one native BlockList, both return the full size. The GC sums external memory contributions across all heap objects, so total reported = 2x actual usage. For N references, it is Nx actual.
Why existing code does not prevent it: The old division by ref_count.get() was the attempt to distribute accounting (size/2 + size/2 = size when ref_count=2), but it fatally broke when ref_count reached 0, causing SIGFPE. The new code correctly removes the division to fix the crash but leaves double-counting unaddressed.
Addressing the refutation: The refutation argues that for cross-worker structured clone (independent GC heaps), each heap independently holding a live reference makes reporting the full size more correct. This is a reasonable position for the cross-heap case. However, it does not cover the same-heap case: if structured clone is used within the same JS context (permitted by the API), both wrappers land in the same GC heap, which then sees 2x the actual footprint with no counterpart to cancel it. The over-estimation is unconditional because the code cannot distinguish same-heap from cross-heap at this call site.
How to fix it and step-by-step proof: The Blob Store pattern (src/bun.js/webcore/blob/Store.zig lines 12-18) is the established precedent: if (this.hasOneRef()) return full_size else 0. Applied here: return if (this.ref_count.hasOneRef()) @sizeof(@this()) + this.estimated_size.load(.seq_cst) else 0. (1) Single wrapper, ref_count=1: hasOneRef() is true, reports full size. Correct. (2) After structured clone, ref_count=2: hasOneRef() is false for both wrappers, both report 0. GC sees 0 total instead of 2x. Slight under-count, but avoids the Nx over-count. (3) When one wrapper is GC-collected, deref() decrements ref_count to 1; the surviving wrapper again reports the full size. Correct again.
Impact: GC over-estimation is a heuristic concern, not a correctness bug. It triggers more frequent GC cycles without causing crashes or incorrect behavior. The structured clone path for BlockList is uncommon, making this a nit-level issue. The PR is a clear net improvement over the SIGFPE crash, but a follow-up adopting the Blob Store pattern would fully resolve the accounting.
|
✅ Verified by robobun: Fix removes the only division-by-ref_count in any estimatedSize across the codebase (confirmed 20+ implementations). Test is new (not on main) and exercises the GC crash path — process survival without SIGFPE is the assertion. CI Build #41047 in progress; prior Build #41024 failures were bundler_compile.test.ts timeouts on Linux, unrelated to this one-line BlockList fix. Diff is clean (no TODO/FIXME/HACK). Bot reviews resolved (style nits addressed in follow-up commits). |
There was a problem hiding this comment.
LGTM — the one-line fix is correct, all prior feedback has been addressed, and the test is clean.
Extended reasoning...
Overview
This PR touches two files: src/bun.js/node/net/BlockList.zig (one-line change to estimatedSize) and a new regression test test/js/node/net/blocklist-gc.test.ts.
Security risks
None. The change removes an arithmetic operation that could cause a fatal signal; it does not affect auth, crypto, or permissions.
Level of scrutiny
Low. The fix is minimal and obviously correct — removing a division by a value that can be zero is the right call. No other estimatedSize in the codebase divides by ref_count, confirming this was an anomaly. The test exercises the exact crash path and is now clean (module-scope import, no tautological assertion).
Other factors
All feedback from previous review rounds has been addressed: the inline require("net") was replaced with a module-scope import (commit 2435525), and the tautological expect(true).toBe(true) was removed (commit a0034b4). The remaining inline comment about the hasOneRef() pattern for structured-clone double-counting is a nit-level follow-up improvement, not a correctness issue, and does not block this PR.
be27f00 to
69c6f6f
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
test/js/node/net/blocklist-gc.test.ts (1)
5-6:⚠️ Potential issue | 🟡 MinorRemove inline bug-context comments from the test body.
Keep the test body focused on setup/action only; bug context should stay in PR/commit metadata.
♻️ Suggested cleanup
test("BlockList does not crash during GC", () => { - // Create and discard BlockList instances to trigger GC collection. - // The test passes if the process survives without SIGFPE. for (let i = 0; i < 10; i++) { const bl = new BlockList(); bl.addAddress("1.2.3.4"); } Bun.gc(true); });Based on learnings: In oven-sh/bun regression/unit test files under
test/js/node/**(e.g.,**/*.test.ts), avoid adding inline comments inside the test body that restate the bug context or reference the issue/PR number being tested.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/js/node/net/blocklist-gc.test.ts` around lines 5 - 6, Remove the inline bug-context comments inside the test body (the two comment lines starting with "Create and discard BlockList instances..." and "The test passes if the process survives without SIGFPE."); leave only the test setup/action code that creates/discards the BlockList instances, and move any explanatory bug context into the PR/commit message or test metadata instead of embedding it in the test body.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@test/js/node/net/blocklist-gc.test.ts`:
- Around line 5-6: Remove the inline bug-context comments inside the test body
(the two comment lines starting with "Create and discard BlockList instances..."
and "The test passes if the process survives without SIGFPE."); leave only the
test setup/action code that creates/discards the BlockList instances, and move
any explanatory bug context into the PR/commit message or test metadata instead
of embedding it in the test body.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: cf00ea17-a3f1-4589-b3fb-7ba0c9a76673
📥 Commits
Reviewing files that changed from the base of the PR and between dbbe22472d0b384bfc343ad96bd6f409de6150ad and 69c6f6f79d2f3d46a1f9d53fb7eed63ccee34679.
📒 Files selected for processing (2)
src/bun.js/node/net/BlockList.zigtest/js/node/net/blocklist-gc.test.ts
There was a problem hiding this comment.
LGTM — the fix is correct and the test nits from my prior reviews have been addressed.
Extended reasoning...
Overview
One-line change in src/bun.js/node/net/BlockList.zig removes the division by ref_count.get() from estimatedSize(), plus a new regression test in test/js/node/net/blocklist-gc.test.ts.
Security risks
None. estimatedSize() is a GC-heuristic callback that returns a usize memory footprint. Removing the division has no security implications.
Level of scrutiny
Low. The fix is a single arithmetic expression change on a well-understood code path. The bug (division by zero when ref_count is 0 on x86-64) is clearly real — IDIV raises SIGFPE on that architecture. No other estimatedSize implementation in the codebase divides by ref_count, confirming the original code was an anomaly.
Other factors
My prior inline comments flagged a style nit (inline require) and a tautological assertion — both were addressed in follow-up commits. The remaining double-counting observation (hasOneRef pattern) is a heuristic nit I explicitly characterized as minor; it does not warrant blocking this crash fix. CI failures in bundler_compile.test.ts are pre-existing Linux timeouts unrelated to this change.
69c6f6f to
53ebe84
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
test/js/node/net/blocklist-gc.test.ts (1)
5-6:⚠️ Potential issue | 🟡 MinorRemove inline bug-context comments in the test body.
Line 5 and Line 6 restate PR/bug context; please keep only setup/action/assertion code here.
♻️ Suggested cleanup
test("BlockList does not crash during GC", () => { - // Create and discard BlockList instances to trigger GC collection. - // The test passes if the process survives without SIGFPE. for (let i = 0; i < 10; i++) { const bl = new BlockList(); bl.addAddress("1.2.3.4"); } Bun.gc(true); });Based on learnings: In
test/js/node/**regression/unit tests, avoid inline comments in test bodies that restate bug context or PR references.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/js/node/net/blocklist-gc.test.ts` around lines 5 - 6, In the test file blocklist-gc.test.ts remove the two inline comment lines that restate PR/bug context ("Create and discard BlockList instances to trigger GC collection." and "The test passes if the process survives without SIGFPE.") from the test body so only setup/action/assertion code remains; keep the test logic that creates/discards BlockList instances and the assertion that the process survives, but delete the contextual comments to comply with the test style for test/js/node/** regression/unit tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@test/js/node/net/blocklist-gc.test.ts`:
- Around line 5-6: In the test file blocklist-gc.test.ts remove the two inline
comment lines that restate PR/bug context ("Create and discard BlockList
instances to trigger GC collection." and "The test passes if the process
survives without SIGFPE.") from the test body so only setup/action/assertion
code remains; keep the test logic that creates/discards BlockList instances and
the assertion that the process survives, but delete the contextual comments to
comply with the test style for test/js/node/** regression/unit tests.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: c316ad16-0088-4ffd-81b8-c0a618965594
📥 Commits
Reviewing files that changed from the base of the PR and between 69c6f6f79d2f3d46a1f9d53fb7eed63ccee34679 and 53ebe8437321fc25f400de053d915230f42068f6.
📒 Files selected for processing (2)
src/bun.js/node/net/BlockList.zigtest/js/node/net/blocklist-gc.test.ts
There was a problem hiding this comment.
LGTM — the fix is correct and the regression test looks good.
Extended reasoning...
Overview
Two-file change: removes a division by ref_count.get() in BlockList.estimatedSize (Zig) and adds a GC regression test (TypeScript). The diff is minimal and targeted.
Security risks
None. This is a crash-fix in a memory-accounting helper; no auth, crypto, or permission logic is touched.
Level of scrutiny
Low. The fix is a single-operand removal from an arithmetic expression. The logic is easy to verify: estimatedSize should return the object's footprint, which is independent of how many references exist. No other estimatedSize in the codebase divides by ref_count.
Other factors
Previous style nits I raised (inline require(), tautological assertion) were addressed in follow-up commits and marked resolved. The structured-clone over-estimation I noted is a pre-existing concern that predates this PR and is not introduced by this change — the PR description explicitly calls this out. CI failures are in bundler_compile.test.ts across multiple platforms and are unrelated to this one-line BlockList fix.
|
CI failures are all darwin infrastructure issues (2 expired agents, 1 build killed with exit -1). All 52 other checks passed including all Linux, Windows, and Alpine test steps. No test failures. |
There was a problem hiding this comment.
LGTM — all prior feedback addressed, fix is correct.
Extended reasoning...
Overview
Two-file change: a one-line Zig fix in BlockList.estimatedSize and a new regression test. The fix removes a division by ref_count.get() that produced SIGFPE when the GC called estimatedSize after the ref-count was decremented to zero on another thread.
Security risks
None. estimatedSize is a GC hint returning a usize; no auth, crypto, or permission logic is touched.
Level of scrutiny
Low. The change is a single arithmetic expression removal with a clear, well-understood root cause. No other estimatedSize implementation in the codebase uses ref-count division, confirming this was an anomaly. The regression test exercises the crash path directly.
Other factors
Previous review rounds flagged: (1) inline require() inside the test body → fixed with module-scope import { BlockList } from "node:net", (2) tautological expect(true).toBe(true) → removed entirely. The double-counting heuristic concern I noted at line 29 was explicitly characterized as a nit and a follow-up improvement, not a correctness or safety issue. CI passes on all Linux, Windows, and Alpine steps; darwin failures are expired-agent infrastructure issues unrelated to this change.
46ab5b9 to
8eb92f3
Compare
There was a problem hiding this comment.
LGTM — the fix is correct and all prior feedback has been addressed.
Extended reasoning...
Overview
Two files changed: a one-line fix in src/bun.js/node/net/BlockList.zig removing the division by ref_count.get() from estimatedSize(), and a new regression test test/js/node/net/blocklist-gc.test.ts.
Security risks
None. The change removes a crash (SIGFPE) and adds no new API surface, permissions logic, or external data handling.
Level of scrutiny
This is a minimal, targeted crash fix. The root cause is clear: integer division by ref_count.get() when the count is 0 raises SIGFPE on x86-64. No other estimatedSize in the codebase uses ref-count division. The fix is the obvious correct solution.
Other factors
All feedback from previous review rounds has been addressed: the require("net") was replaced with a module-scope import, the tautological expect(true).toBe(true) assertion was removed. The remaining CodeRabbit nit about inline comments in the test body is non-blocking. CI failures are darwin infrastructure issues (expired agents), not test failures. The double-counting heuristic concern I raised as an inline comment is documented for follow-up but is not a correctness issue blocking this fix.
|
All 57 non-darwin checks passed. The 4 darwin failures are all |
8eb92f3 to
e4c97be
Compare
There was a problem hiding this comment.
LGTM — all prior review concerns have been addressed.
Extended reasoning...
Overview
Two-file change: a one-line fix in src/bun.js/node/net/BlockList.zig removing a division by ref_count.get() in estimatedSize(), plus a new regression test test/js/node/net/blocklist-gc.test.ts.
Security risks
None. This is a crash fix for integer division by zero, not touching auth, crypto, or permissions.
Level of scrutiny
Low — the change is minimal and mechanical. The root cause (division by a value that can be zero) is straightforward, and the fix (remove the division) is correct. No other estimatedSize implementation in the codebase divides by ref_count.
Other factors
All feedback from prior review rounds has been incorporated: module-scope import is used, the tautological expect(true).toBe(true) assertion was removed (process survival is the implicit assertion for crash regression tests), and CI passed on all 57 non-darwin checks. Darwin failures are agent availability issues unrelated to this change.
Remove division by ref_count.get() in BlockList.estimatedSize which can be zero when the GC calls estimatedSize on an object whose ref_count has been decremented by another thread. Integer division by zero raises SIGFPE on x86-64. No other estimatedSize implementation divides by ref_count.
89471a4 to
f139fff
Compare
|
Closing this PR. The fix (removing division by |
There was a problem hiding this comment.
LGTM — all prior feedback was addressed and the fix is correct.
Extended reasoning...
Overview
Two-file change: a one-line fix in src/bun.js/node/net/BlockList.zig removing the division by ref_count.get() in estimatedSize(), plus a new regression test in test/js/node/net/blocklist-gc.test.ts.
Security risks
None. This is a crash fix in GC bookkeeping; it has no auth, crypto, or permission implications.
Level of scrutiny
Low — the change is minimal, the root cause (integer division by zero when ref_count=0) is well-understood, and no other estimatedSize implementation in the codebase divides by ref_count. The fix aligns with the established pattern across 20+ sibling implementations.
Other factors
All feedback from previous review rounds was addressed: the require("net") inside the test body was replaced with a module-scope import { BlockList } from "node:net", the tautological expect(true).toBe(true) assertion was removed, and the test now correctly relies on process survival as its pass condition. All 57 non-darwin CI checks passed; darwin failures were agent expiration issues unrelated to this change. The hasOneRef() double-counting note I left is a valid follow-up improvement but is a separate, pre-existing concern and not a blocker.
BlockList.estimatedSizedivided byref_count.get(), which can be zero when the GC callsestimatedSizeon an object whose ref_count has already been decremented by another thread. Integer division by zero on x86-64 raises SIGFPE (signal 8).No other
estimatedSizeimplementation in the codebase divides by ref_count — the total memory footprint of the object does not change based on how many references exist. This removes the division.Before:
After:
Verification (robobun): Confirmed main:BlockList.zig line 28 has the division by ref_count.get(); PR removes it. Diff is exactly 2 files (one-line Zig fix + 12-line regression test), no TODO/FIXME/HACK. Verified no other estimatedSize (20+ implementations) divides by ref_count. Test file does not exist on main, uses module-scope import, creates/discards BlockList instances then forces Bun.gc(true) — would SIGFPE on main, survives after fix. CI Build #41170 pending; prior failures were darwin infra issues and bundler_compile.test.ts timeouts, unrelated to BlockList. Bot reviews: CodeRabbit only remaining nit is inline comments in test body (non-blocking style); Claude LGTM multiple rounds.