Skip to content

Commit

Permalink
fix finish on server side
Browse files Browse the repository at this point in the history
  • Loading branch information
cirospaciari committed Oct 15, 2024
1 parent 794ebe5 commit 7196d23
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 41 deletions.
49 changes: 12 additions & 37 deletions src/bun.js/api/bun/h2_frame_parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -978,17 +978,14 @@ pub const H2FrameParser = struct {
if (this.waitForTrailers) {
client.dispatch(.onWantTrailers, this.getIdentifier());
} else {
const identifier = this.getIdentifier();
identifier.ensureStillAlive();
if (this.state == .HALF_CLOSED_REMOTE) {
this.state = .CLOSED;
} else {
this.state = .HALF_CLOSED_LOCAL;
}
if (this.state == .CLOSED) {
const identifier = this.getIdentifier();
identifier.ensureStillAlive();
this.freeResources(client, false);
client.dispatchWithExtra(.onStreamEnd, identifier, JSC.JSValue.jsNumber(@intFromEnum(this.state)));
}
client.dispatchWithExtra(.onStreamEnd, identifier, JSC.JSValue.jsNumber(@intFromEnum(this.state)));
}
}
}
Expand Down Expand Up @@ -2852,9 +2849,7 @@ pub const H2FrameParser = struct {
} else {
stream.state = .HALF_CLOSED_LOCAL;
}
if (stream.state == .CLOSED) {
this.dispatchWithExtra(.onStreamEnd, identifier, JSC.JSValue.jsNumber(@intFromEnum(stream.state)));
}
this.dispatchWithExtra(.onStreamEnd, identifier, JSC.JSValue.jsNumber(@intFromEnum(stream.state)));
}
}
}
Expand Down Expand Up @@ -2947,17 +2942,15 @@ pub const H2FrameParser = struct {
stream.waitForTrailers = false;
this.sendData(stream, "", true, JSC.JSValue.jsUndefined());

const identifier = stream.getIdentifier();
identifier.ensureStillAlive();
if (stream.state == .HALF_CLOSED_REMOTE) {
stream.state = .CLOSED;
stream.freeResources(this, false);
} else {
stream.state = .HALF_CLOSED_LOCAL;
}
if (stream.state == .CLOSED) {
const identifier = stream.getIdentifier();
identifier.ensureStillAlive();
stream.freeResources(this, false);
this.dispatchWithExtra(.onStreamEnd, identifier, JSC.JSValue.jsNumber(@intFromEnum(stream.state)));
}
this.dispatchWithExtra(.onStreamEnd, identifier, JSC.JSValue.jsNumber(@intFromEnum(stream.state)));
return .undefined;
}

Expand Down Expand Up @@ -3104,17 +3097,15 @@ pub const H2FrameParser = struct {
const writer = this.toWriter();
_ = frame.write(@TypeOf(writer), writer);
_ = writer.write(buffer[0..encoded_size]) catch 0;
const identifier = stream.getIdentifier();
identifier.ensureStillAlive();
if (stream.state == .HALF_CLOSED_REMOTE) {
stream.state = .CLOSED;
stream.freeResources(this, false);
} else {
stream.state = .HALF_CLOSED_LOCAL;
}
if (stream.state == .CLOSED) {
const identifier = stream.getIdentifier();
identifier.ensureStillAlive();
stream.freeResources(this, false);
this.dispatchWithExtra(.onStreamEnd, identifier, JSC.JSValue.jsNumber(@intFromEnum(stream.state)));
}
this.dispatchWithExtra(.onStreamEnd, identifier, JSC.JSValue.jsNumber(@intFromEnum(stream.state)));
return .undefined;
}
pub fn writeStream(this: *H2FrameParser, globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) JSValue {
Expand Down Expand Up @@ -3908,22 +3899,6 @@ pub const H2FrameParser = struct {
}
this.streams.deinit();
}
// pub fn ref(this: *H2FrameParser) void {
// this.ref_count += 1;
// log("ref {}", .{this.ref_count});
// }

// pub fn unref(this: *H2FrameParser) void {
// const ref_count = this.ref_count;
// log("unref {}", .{ref_count});

// bun.assert(ref_count > 0);
// this.ref_count -= 1;

// if (ref_count == 1) {
// this.deinit();
// }
// }

pub fn finalize(
this: *H2FrameParser,
Expand Down
8 changes: 4 additions & 4 deletions src/js/node/http2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1659,10 +1659,10 @@ enum StreamState {
WritableClosed = 1 << 5, // 100000 = 32
}
function markWritableDone(stream: Http2Stream) {
const final = stream[bunHTTP2StreamFinal];
if (typeof final === "function") {
const _final = stream[bunHTTP2StreamFinal];
if (typeof _final === "function") {
stream[bunHTTP2StreamFinal] = null;
final();
_final();
stream[bunHTTP2StreamStatus] |= StreamState.WritableClosed | StreamState.FinalCalled;
return;
}
Expand Down Expand Up @@ -2443,7 +2443,7 @@ class ServerHttp2Session extends Http2Session {
if (self.#connections === 0 && self.#closed) {
self.destroy();
}
} else if (state === 5) {
} else if (state === 6) {
// 5 = local closed aka write is closed
markWritableDone(stream);
}
Expand Down

0 comments on commit 7196d23

Please sign in to comment.