Skip to content

Commit

Permalink
fix part start
Browse files Browse the repository at this point in the history
  • Loading branch information
cirospaciari committed Dec 28, 2024
1 parent 4d381cf commit 7383651
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 14 deletions.
14 changes: 8 additions & 6 deletions src/s3.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1813,7 +1813,7 @@ pub const MultiPartUpload = struct {
}, .{ .part = @ptrCast(&onPartResponse) }, this);
}
pub fn start(this: *@This()) void {
if (this.state != .pending) return;
if (this.state != .pending or this.ctx.state != .multipart_completed) return;
this.ctx.ref();
this.state = .started;
this.perform();
Expand Down Expand Up @@ -1925,10 +1925,12 @@ pub const MultiPartUpload = struct {

fn drainEnqueuedParts(this: *@This()) void {
// check pending to start or transformed buffered ones into tasks
for (this.queue.items) |*part| {
if (part.state == .pending) {
// lets start the part request
part.start();
if (this.state == .multipart_completed) {
for (this.queue.items) |*part| {
if (part.state == .pending) {
// lets start the part request
part.start();
}
}
}
const partSize = this.partSizeInBytes();
Expand Down Expand Up @@ -2099,7 +2101,7 @@ pub const MultiPartUpload = struct {
.search_params = "?uploads=",
.content_type = this.content_type,
}, .{ .download = @ptrCast(&startMultiPartRequestResult) }, this);
} else {
} else if (this.state == .multipart_completed) {
part.start();
}
return true;
Expand Down
1 change: 0 additions & 1 deletion test/js/bun/s3/bun-write-leak-fixture.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion test/js/bun/s3/s3-stream-leak-fixture.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion test/js/bun/s3/s3-writer-leak-fixture.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions test/js/bun/s3/s3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe.skipIf(!s3Options.accessKeyId)("s3", () => {
// 15 MiB big enough to Multipart upload in more than one part
const buffer = Buffer.alloc(1 * 1024 * 1024, "a");
{
await fetch(tmp_filename + "-large", {
await fetch(tmp_filename, {
method: "PUT",
body: async function* () {
for (let i = 0; i < 15; i++) {
Expand All @@ -120,12 +120,9 @@ describe.skipIf(!s3Options.accessKeyId)("s3", () => {
s3: options,
}).then(res => res.text());

const result = await fetch(tmp_filename + "-large", { method: "HEAD", s3: options });

const result = await fetch(tmp_filename, { method: "HEAD", s3: options });
expect(result.status).toBe(200);
expect(result.headers.get("content-length")).toBe("15728640");

await fetch(tmp_filename + "-large", { method: "DELETE", s3: options });
}
}, 10_000);
});
Expand Down

0 comments on commit 7383651

Please sign in to comment.