-
Notifications
You must be signed in to change notification settings - Fork 5k
Unpin ArrayBuffers without classInfo() so blob finalizers are safe during GC sweep #37008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,46 @@ | ||
| import { expect, test } from "bun:test"; | ||
| import { bunEnv, bunExe, normalizeBunSnapshot } from "harness"; | ||
|
|
||
| test.concurrent("collecting file blobs with Buffer paths does not crash during GC sweep", async () => { | ||
| // The S3/file blob store keeps the pinned path buffer until the wrapper is | ||
| // finalized inside the GC sweep; releasing the pin must not reach | ||
| // JSCell::classInfo() there (validateIsNotSweeping assert in debug builds). | ||
| const fixture = ` | ||
| const enc = new TextEncoder(); | ||
| for (let i = 0; i < 50; i++) { | ||
| new Bun.S3Client({}).file(Buffer.from("key-" + i)); | ||
| new Bun.S3Client({}).file(new DataView(enc.encode("dv-key-" + i).buffer)); | ||
| new Bun.S3Client({}).file(enc.encode("uint8-key-" + i)); | ||
| Bun.file(Buffer.from("/tmp/buffer-path-" + i)); | ||
| Bun.file(enc.encode("/tmp/uint8-path-" + i)); | ||
| Bun.file(enc.encode("/tmp/enc-path-" + i).buffer); | ||
| Bun.gc(true); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
| console.log("ok"); | ||
| `; | ||
|
|
||
| await using proc = Bun.spawn({ | ||
| cmd: [bunExe(), "-e", fixture], | ||
| env: bunEnv, | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
|
|
||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
|
|
||
| expect({ | ||
| stdout: normalizeBunSnapshot(stdout), | ||
| stderr: normalizeBunSnapshot(stderr), | ||
| exitCode, | ||
| }).toMatchInlineSnapshot(` | ||
| { | ||
| "exitCode": 0, | ||
| "stderr": "", | ||
| "stdout": "ok", | ||
| } | ||
| `); | ||
|
Comment on lines
+31
to
+41
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win Do not require empty
Based on learnings: avoid Proposed assertion change- const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
+ const [stdout, , exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
expect({
stdout: normalizeBunSnapshot(stdout),
- stderr: normalizeBunSnapshot(stderr),
exitCode,
}).toMatchInlineSnapshot(`
{
"exitCode": 0,
- "stderr": "",
"stdout": "ok",
}
`);🤖 Prompt for AI AgentsSource: Learnings |
||
| }); | ||
|
|
||
| test("S3 stream error parked before consumption survives GC", async () => { | ||
| const fixture = ` | ||
| const stream = Bun.S3Client.file("some-key").stream(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you need a paragraph-long comment to justify why the workaround is OK, the code is wrong — fix the code