Skip to content
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
20 changes: 17 additions & 3 deletions test/js/bun/http/proxy-stress-protocol.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@

describe("early reply during upload", () => {
async function makeEarlyReplyOrigin(status: number, after: number, withTls: boolean) {
const sockets = new Set<net.Socket>();
const handler = (sock: net.Socket) => {
sockets.add(sock);
sock.on("close", () => sockets.delete(sock));
sock.on("error", () => {});
let got = 0;
let replied = false;
Expand All @@ -60,8 +63,15 @@
got += chunk.length;
if (!replied && got >= after) {
replied = true;
const reply = `HTTP/1.1 ${status} Nope\r\nContent-Length: 5\r\nConnection: close\r\n\r\nearly`;
sock.write(reply, () => sock.end());
// Keep the socket open after replying: the client is still
// mid-upload, and if we end here the proxy relays the FIN and
// closes the client leg while ~1MB of body is still in flight.
// bun's next on_writable then observes a shut-down socket before
// it has read this response and fails with ConnectionClosed
// (ECONNRESET). The client closes after reading Connection: close,
// which tears down the proxy→origin leg.
sock.write(reply);

Check warning on line 74 in test/js/bun/http/proxy-stress-protocol.test.ts

View check run for this annotation

Claude / Claude Code Review

Deflake may route around a runtime bug it exposed

The PR's own root-cause analysis names a bun runtime code path (`send_initial_request_payload`'s `is_closed() || is_shutdown()` guard / `on_close` firing before buffered response bytes are parsed) as the failure mechanism, and the removed scenario — origin sends early error + `Connection: close` + immediate FIN, proxy relays the close mid-upload — is realistic (nginx behind a forward proxy does exactly this for 413). Per REVIEW.md ("Never edit a test to route around a runtime bug it exposed"), t
Comment thread
claude[bot] marked this conversation as resolved.
Resolved
}
});
};
Expand All @@ -71,11 +81,15 @@
server.listen(0, "127.0.0.1");
await once(server, "listening");
const port = (server.address() as net.AddressInfo).port;
const close = () => {
server.close();
for (const s of sockets) s.destroy();
};
return {
url: `${withTls ? "https" : "http"}://localhost:${port}`,
port,
close: () => server.close(),
[Symbol.asyncDispose]: async () => server.close(),
close,
[Symbol.asyncDispose]: async () => close(),
};
}

Expand Down
Loading