-
Notifications
You must be signed in to change notification settings - Fork 5k
s3: fix path double-deinit when operation throws after store creation #30567
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
Closed
Closed
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
94b41ae
s3: fix path double-deinit when operation throws after store creation
robobun 455c262
add test coverage for presign expiresIn and type getter throwing insi…
robobun f9cb610
test: use explicit credentials to avoid env-dependent presign behavior
robobun fb1a44c
test: cover Bun.file('s3://') and S3Client.file with throwing type ge…
robobun f03a4c2
ci: retrigger
robobun 446fdf7
test: make type-getter test throw on second read so it fires after in…
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { expect, test } from "bun:test"; | ||
|
|
||
| // When a later step of an S3 operation throws after the blob store has taken | ||
| // ownership of the path string, the caller's `errdefer path.deinit()` used to | ||
| // run as well, over-dereffing the path's WTFStringImpl (whose ref had already | ||
| // been transferred by `toThreadSafe()` inside `Store.initS3`). | ||
| const throwing = { | ||
| [Symbol.toPrimitive]() { | ||
| throw new Error("boom"); | ||
| }, | ||
| }; | ||
|
|
||
| const opts = { accessKeyId: "a", secretAccessKey: "b", bucket: "c", endpoint: "http://localhost:1" }; | ||
|
|
||
| test("S3Client#write propagates data coercion errors without crashing", () => { | ||
| const s3 = new Bun.S3Client(opts); | ||
| expect(() => s3.write("ab", throwing)).toThrow("boom"); | ||
| expect(() => s3.write("some/longer/path", [throwing, throwing])).toThrow("boom"); | ||
| }); | ||
|
|
||
| test("S3Client.write (static) propagates data coercion errors without crashing", () => { | ||
| expect(() => Bun.S3Client.write("ab", throwing, opts)).toThrow("boom"); | ||
| expect(() => Bun.S3Client.write("some/longer/path", [throwing], opts)).toThrow("boom"); | ||
| }); | ||
|
|
||
| test("S3Client presign with invalid expiresIn does not crash", () => { | ||
| expect(() => Bun.S3Client.presign("some/path", { ...opts, expiresIn: -1 })).toThrow("expiresIn"); | ||
| expect(() => Bun.S3Client.presign("\u{1F600}/path", { ...opts, expiresIn: -1 })).toThrow("expiresIn"); | ||
| const s3 = new Bun.S3Client(opts); | ||
| expect(() => s3.presign("some/path", { expiresIn: -1 })).toThrow("expiresIn"); | ||
| expect(() => s3.presign("ab", { expiresIn: -1 })).toThrow("expiresIn"); | ||
| }); | ||
|
|
||
| test("S3 file construction with options.type getter throwing does not crash", () => { | ||
| const throwingType = { | ||
| get type() { | ||
| throw new Error("type-boom"); | ||
| }, | ||
| }; | ||
| const s3 = new Bun.S3Client(opts); | ||
| expect(() => s3.file("some/path", throwingType)).toThrow("type-boom"); | ||
| expect(() => Bun.file("s3://bucket/some/path", throwingType)).toThrow("type-boom"); | ||
| expect(() => Bun.S3Client.file("some/path", throwingType)).toThrow("type-boom"); | ||
| }); | ||
|
Check warning on line 44 in test/js/bun/s3/s3-write-throwing-data.test.ts
|
||
|
claude[bot] marked this conversation as resolved.
Outdated
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.