{"record":{"id":"e661087864725970","repo":"windmill-labs/windmill","slug":"bad-gateway-e66108","errorCode":null,"errorMessage":"Bad Gateway","messagePattern":"Bad Gateway","errorType":"http","errorClass":null,"httpStatus":502,"severity":"error","filePath":"multiplayer/gateway.mjs","lineNumber":69,"sourceCode":"  const { port, path } = resolve(clientReq.url)\n\n  const opts = {\n    hostname: '127.0.0.1',\n    port,\n    path,\n    method: clientReq.method,\n    headers: clientReq.headers,\n  }\n\n  const proxy = http.request(opts, (proxyRes) => {\n    clientRes.writeHead(proxyRes.statusCode, proxyRes.headers)\n    proxyRes.pipe(clientRes, { end: true })\n  })\n\n  proxy.on('error', (err) => {\n    console.error(`[gateway] HTTP proxy error → :${port}${path}: ${err.message}`)\n    if (!clientRes.headersSent) {\n      clientRes.writeHead(502, { 'Content-Type': 'text/plain' })\n    }\n    clientRes.end('Bad Gateway')\n  })\n\n  clientReq.pipe(proxy, { end: true })\n})\n\n// ---- WebSocket proxy (upgrade) ----\n\nserver.on('upgrade', (clientReq, clientSocket, head) => {\n  const { port, path } = resolve(clientReq.url)\n\n  const opts = {\n    hostname: '127.0.0.1',\n    port,\n    path,\n    method: 'GET',\n    headers: clientReq.headers,","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/multiplayer/gateway.mjs#L51-L87","documentation":"multiplayer/gateway.mjs runs an HTTP proxy in front of per-instance multiplayer servers. Its proxy 'error' handler writes a 502 (if headers were not already sent) and ends the response with 'Bad Gateway'. It means the gateway could not complete the proxied request to the target port.","triggerScenarios":"A request arrives at the gateway and is proxied to :<port><path>, but the target connection errors: nothing listening on that port, ECONNRESET from the instance server, or the socket closing before a response.","commonSituations":"Multiplayer instance container/process not started yet or already stopped; stale routing table pointing at a dead port; instance crashing under load and resetting connections; port mapping mismatch between gateway and instances.","solutions":["Check gateway logs for '[gateway] HTTP proxy error' — the message names the target port and path","Verify the instance server is running and listening on the port the gateway routed to","Fix or refresh the instance registry/routing entry so it points at a live port","Retry the request once the instance is healthy"],"exampleFix":"// before\ncurl http://gateway/room/1  # instance on :7103 is down → 502\n// after\ndocker start multiplayer-instance-7103  # then retry; gateway proxies successfully","handlingStrategy":"retry","validationCode":"// before routing to an instance port, probe it\nconst healthy = await fetch(`http://127.0.0.1:${port}/health`).then(r => r.ok).catch(() => false);\nif (!healthy) throw new Error(`multiplayer instance on :${port} is not up`);","typeGuard":null,"tryCatchPattern":"try {\n  const res = await fetch(gatewayUrl + path);\n  if (res.status === 502) {\n    // instance down; re-check registry and retry after restart\n  }\n} catch (err) { /* network-level failure of the gateway itself */ }","preventionTips":["Ensure instance servers register with the gateway only after listening","Add readiness probes so traffic routes only to live ports","Monitor gateway logs for '[gateway] HTTP proxy error' lines","Use supervisor/restart policies for instance processes"],"tags":["network","proxy","http-502","multiplayer","gateway"],"backgroundTag":"bad-gateway-502","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}