fix: Do not report writes to a closing websocket (#14446)

Fixes OUTLINE-CLOUD-DAD
This commit is contained in:
Tom Moor authored and GitHub committed 2026-11-02 08:42:01 -05:00
1 parent b3eeaea035
commit de8952d80b
2 files changed
+31 -1

No files matched your search

+15
View File
@@ -28,6 +28,21 @@ describe("onupgrade", () => {
errorSpy.mockRestore();
});
it("should swallow writes to a socket that has already ended", async () => {
const errorSpy = vi.spyOn(Logger, "error");
const server = http.createServer();
const socket = new PassThrough();
onupgrade(server);
server.emit("upgrade", request(), socket);
socket.end();
socket.write("message");
await new Promise((resolve) => setImmediate(resolve));
expect(errorSpy).not.toHaveBeenCalled();
errorSpy.mockRestore();
});
it("should report unexpected errors", () => {
const errorSpy = vi.spyOn(Logger, "error").mockImplementation(() => {});
const server = http.createServer();
+16 -1
View File
@@ -63,4 +63,19 @@ export function rejectUpgrade(socket: Duplex) {
* Socket errors that are the result of a client, or an intermediary such as a
* reverse proxy, going away. They are expected and not worth reporting.
*/
const expectedErrorCodes = ["ECONNRESET", "ECONNABORTED", "EPIPE", "ETIMEDOUT"];
const expectedErrorCodes = [
// The client closed the connection abruptly.
"ECONNRESET",
// The connection was aborted before it was established.
"ECONNABORTED",
// A write was attempted after the client closed the connection.
"EPIPE",
// The client stopped responding.
"ETIMEDOUT",
// A message was broadcast to a websocket that was already closing.
"ERR_STREAM_WRITE_AFTER_END",
];