{"record":{"id":"479dc3aa701e19a5","repo":"windmill-labs/windmill","slug":"bad-gateway","errorCode":null,"errorMessage":"Bad Gateway","messagePattern":"Bad Gateway","errorType":"http","errorClass":null,"httpStatus":502,"severity":"error","filePath":"cli/src/commands/dev/dev.ts","lineNumber":873,"sourceCode":"        path: clientReq.url,\n        method: clientReq.method,\n        headers: fwdHeaders,\n      };\n\n      const proxyReq = httpModule.request(proxyOpts, (proxyRes) => {\n        const setCookie = proxyRes.headers[\"set-cookie\"];\n        if (setCookie) {\n          proxyRes.headers[\"set-cookie\"] = setCookie.map((cookie) =>\n            cookie.replace(/domain=[^;]+/gi, \"domain=localhost\")\n          );\n        }\n        clientRes.writeHead(proxyRes.statusCode ?? 502, proxyRes.headers);\n        proxyRes.pipe(clientRes, { end: true });\n      });\n\n      proxyReq.on(\"error\", (err) => {\n        console.error(\"Proxy error:\", err.message);\n        clientRes.writeHead(502);\n        clientRes.end(\"Bad Gateway\");\n      });\n\n      clientReq.pipe(proxyReq, { end: true });\n    });\n\n    // WebSocket upgrades\n    proxyServer.on(\"upgrade\", (req, socket, head) => {\n      const pathname = req.url?.split(\"?\")[0] ?? \"\";\n\n      if (pathname === \"/ws_dev\" || pathname === \"/ws\") {\n        devWss.handleUpgrade(req, socket, head, (ws) => {\n          devWss.emit(\"connection\", ws, req);\n        });\n        return;\n      }\n\n      if (pathname.startsWith(\"/ws/\") || pathname.startsWith(\"/ws_mp/\") || pathname.startsWith(\"/ws_debug/\")) {","sourceCodeStart":855,"sourceCodeEnd":891,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/cli/src/commands/dev/dev.ts#L855-L891","documentation":"The dev proxy in cli/src/commands/dev/dev.ts forwards each client request to an upstream server. When the outbound proxyReq emits an 'error' (target unreachable, connection reset, TLS failure), the handler logs the cause and responds to the client with HTTP 502 and the body 'Bad Gateway'. This is the proxy signaling that the upstream failed, not the client request itself.","triggerScenarios":"Any request proxied to the upstream where the socket errors: upstream port not listening (backend not started or crashed), connection refused/reset, DNS failure, or TLS handshake failure on the target the dev command proxies to.","commonSituations":"Running the dev frontend before the backend is up or after the backend died; wrong REMOTE/port env var; backend restarted mid-request; firewall or VPN blocking the upstream port.","solutions":["Check the terminal running the dev command for the 'Proxy error:' line — the err.message names the real cause","Verify the upstream server (backend) is actually running and listening on the configured port","Confirm the REMOTE/target port env var matches the port the backend binds to","Restart the dev command after the upstream is healthy; retry the request"],"exampleFix":"// before\ncargo run  # not started; proxy calls fail\n// after\ncd backend && cargo run  # wait for 'listening', then run dev frontend","handlingStrategy":"retry","validationCode":"// before issuing requests through the dev proxy, check the upstream is reachable\nconst upstream = process.env.REMOTE ?? 'http://localhost:8000';\nawait fetch(upstream + '/api/version').catch(() => { throw new Error(`upstream ${upstream} not reachable — start the backend first`); });","typeGuard":null,"tryCatchPattern":"// on the client side of the proxy\ntry {\n  const res = await fetch(url);\n  if (res.status === 502) throw new Error('dev proxy upstream failed — is the backend running?');\n} catch (err) { /* surface upstream health message */ }","preventionTips":["Start the backend before the dev frontend/proxy","Check for the proxy's 'Proxy error:' log line to diagnose the real cause","Pin REMOTE/port env vars in one place so proxy and backend agree","Add a startup health check against the upstream before serving"],"tags":["network","proxy","http-502","dev-server"],"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"}