From b290fd01f3f5d32f9d010fc719ced0240759c049 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Thu, 4 Jul 2024 20:19:42 -0700 Subject: fix(ext/node): http chunked writes hangs (#24428) Fixes https://github.com/denoland/deno/issues/24239 --- ext/node/polyfills/http.ts | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'ext/node') diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts index 40155d998..dde7c4e41 100644 --- a/ext/node/polyfills/http.ts +++ b/ext/node/polyfills/http.ts @@ -1349,7 +1349,6 @@ export class ServerResponse extends NodeWritable { // used by `npm:on-finished` finished = false; headersSent = false; - #firstChunk: Chunk | null = null; #resolve: (value: Response | PromiseLike) => void; // deno-lint-ignore no-explicit-any #socketOverride: any | null = null; @@ -1386,28 +1385,25 @@ export class ServerResponse extends NodeWritable { autoDestroy: true, defaultEncoding: "utf-8", emitClose: true, + // FIXME: writes don't work when a socket is assigned and then + // detached. write: (chunk, encoding, cb) => { + // Writes chunks are directly written to the socket if + // one is assigned via assignSocket() if (this.#socketOverride && this.#socketOverride.writable) { this.#socketOverride.write(chunk, encoding); return cb(); } if (!this.headersSent) { - if (this.#firstChunk === null) { - this.#firstChunk = chunk; - return cb(); - } else { - ServerResponse.#enqueue(controller, this.#firstChunk); - this.#firstChunk = null; - this.respond(false); - } + ServerResponse.#enqueue(controller, chunk); + this.respond(false); + return cb(); } ServerResponse.#enqueue(controller, chunk); return cb(); }, final: (cb) => { - if (this.#firstChunk) { - this.respond(true, this.#firstChunk); - } else if (!this.headersSent) { + if (!this.headersSent) { this.respond(true); } controller.close(); -- cgit v1.2.3