Skip to content
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

Fix express responses dying early #18080

Merged
merged 2 commits into from
Mar 12, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/js/node/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const runSymbol = Symbol("run");
const deferredSymbol = Symbol("deferred");
const eofInProgress = Symbol("eofInProgress");
const fakeSocketSymbol = Symbol("fakeSocket");
const finishedSymbol = "finished";
const finishedSymbol = Symbol("finished");
const firstWriteSymbol = Symbol("firstWrite");
const headersSymbol = Symbol("headers");
const isTlsSymbol = Symbol("is_tls");
Expand Down Expand Up @@ -1850,6 +1850,7 @@ function ServerResponse(req, options) {
this._sent100 = false;
this[headerStateSymbol] = NodeHTTPHeaderState.none;
this[kPendingCallbacks] = [];
this[finishedSymbol] = false;

// this is matching node's behaviour
// https://github.com/nodejs/node/blob/cf8c6994e0f764af02da4fa70bc5962142181bf3/lib/_http_server.js#L192
Expand Down Expand Up @@ -1886,6 +1887,13 @@ const ServerResponsePrototype = {
this[headerStateSymbol] = value ? NodeHTTPHeaderState.sent : NodeHTTPHeaderState.none;
},

get finished() {
return this[finishedSymbol];
},
set finished(value) {
this[finishedSymbol] = value;
},

// This end method is actually on the OutgoingMessage prototype in Node.js
// But we don't want it for the fetch() response version.
end(chunk, encoding, callback) {
Expand Down Expand Up @@ -1936,7 +1944,7 @@ const ServerResponsePrototype = {
req._dump();
}
this.detachSocket(socket);
this[finishedSymbol] = this.finished = true;
this.finished = true;

this.emit("prefinish");
this._callPendingCallbacks();
Expand Down