-
Notifications
You must be signed in to change notification settings - Fork 5.1k
FileSink: mark sink done when end() fails during flush #31135
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
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 |
|---|---|---|
|
|
@@ -278,3 +278,33 @@ it("start() without path/fd on an already-open writer does not crash", async () | |
| await writer.end(); | ||
| expect(await Bun.file(path).text()).toBe("hello"); | ||
| }); | ||
|
|
||
| it.skipIf(!isPosix)("writing after end() fails during flush does not crash", async () => { | ||
| const dir = tmpdirSync(); | ||
| const target = join(dir, "ro.txt"); | ||
| fs.writeFileSync(target, ""); | ||
| const writer = Bun.file(target).writer(); | ||
| // Re-point the writer at a read-only fd so the buffered flush in end() fails. | ||
| const fd = fs.openSync(target, "r"); | ||
| try { | ||
| writer.start({ fd }); | ||
| } finally { | ||
| fs.closeSync(fd); | ||
| } | ||
| writer.write("x"); | ||
| let endErr: unknown; | ||
| try { | ||
| await writer.end(); | ||
| } catch (e) { | ||
| endErr = e; | ||
| } | ||
| expect(endErr).toBeDefined(); | ||
| // Previously this would attempt to write to an invalid fd and crash with a | ||
| // debug assertion; now it should behave as if the sink is closed. | ||
| expect(() => writer.write("y")).not.toThrow(); | ||
| expect(() => writer.start({})).not.toThrow(); | ||
| expect(() => writer.write("z")).not.toThrow(); | ||
| expect(() => writer.flush()).not.toThrow(); | ||
| await Promise.resolve(writer.end()).catch(() => {}); | ||
|
Comment on lines
+304
to
+308
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.
Suggested change- expect(() => writer.flush()).not.toThrow();
- await Promise.resolve(writer.end()).catch(() => {});
+ await expect(writer.flush()).resolves.toBeUndefined();
+ await Promise.resolve(writer.end()).catch(() => {});🤖 Prompt for AI Agents |
||
| await 1; | ||
| }); | ||
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.
Use
tempDirfixture instead oftmpdirSyncin this new test.This new test introduces
tmpdirSync(), which is against the repo test harness rule and weakens cleanup guarantees.Suggested change
As per coding guidelines: "
**/*.test.{ts,tsx}: UsetempDirfrom 'harness' to create temporary directories - do not usetmpdirSyncorfs.mkdtempSync."📝 Committable suggestion
🤖 Prompt for AI Agents