Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: skip the refusal write when the upgrade socket is already closed (#8389)

[._.]/ Adam Eivya06b1a165169
diff --git a/server/lib/httpDrain.js b/server/lib/httpDrain.js
index 5eb85d1381..1f7a99e4ee 100644
--- a/server/lib/httpDrain.js
+++ b/server/lib/httpDrain.js
@@ -39,12 +39,13 @@ const refuseDuringDrain = (req, res) => {
// Upgrade requests never reach Express — there is no `res` to write through,
// only the raw socket handed to every 'upgrade' listener.
const refuseUpgradeDuringDrain = (req, socket) => {
- // Write the 503 response. The callback ensures the write is flushed before
- // destroying the socket, preventing data loss if the socket closes immediately
- // after the write is queued (#8389).
- socket.write('HTTP/1.1 503 Service Unavailable\r\nConnection: close\r\n\r\n', () => {
+ if (!socket.writable) {
socket.destroy();
- });
+ return;
+ }
+ // Destroy only once the refusal has flushed: destroying right after a queued
+ // write discards it, and the client reads an empty response (#8389).
+ socket.write('HTTP/1.1 503 Service Unavailable\r\nConnection: close\r\n\r\n', () => socket.destroy());
};
export const createHttpDrain = (servers) => {