Skip to content

Commit 2d0ee43

Browse files
dormouse-botclaude
andcommitted
iframe-proxy: settle collectBody on truncation so error page serves
stream.destroy() (no error arg) emits 'close'/'aborted' but neither 'end' nor 'error', so the listeners that call complete() never fired on the truncation path — the over-limit branch in collectBody's callback was unreachable and the downstream response hung with nothing served. Call complete() explicitly after destroy(), guarded by a 'settled' flag so the normal end/error path can't double-serve. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 72d13a4 commit 2d0ee43

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

vscode-ext/src/iframe-proxy-host.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,16 +235,25 @@ function collectBody(stream: http.IncomingMessage, done: (body: string, truncate
235235
const chunks: Buffer[] = [];
236236
let size = 0;
237237
let truncated = false;
238+
let settled = false;
239+
const complete = () => {
240+
if (settled) return;
241+
settled = true;
242+
done(Buffer.concat(chunks).toString('utf8'), truncated);
243+
};
238244
stream.on('data', (chunk: Buffer) => {
239245
size += chunk.length;
240246
if (size > HTML_BODY_LIMIT) {
241247
truncated = true;
248+
// `destroy()` (no error) emits 'close'/'aborted' but neither 'end' nor
249+
// 'error', so the listeners below would never fire — settle explicitly
250+
// or the downstream response hangs with nothing served.
242251
stream.destroy();
252+
complete();
243253
return;
244254
}
245255
chunks.push(chunk);
246256
});
247-
const complete = () => done(Buffer.concat(chunks).toString('utf8'), truncated);
248257
stream.on('end', complete);
249258
stream.on('error', complete);
250259
}

0 commit comments

Comments
 (0)