(req, socket, head, target)
| 266 | } |
| 267 | |
| 268 | function proxyWebSocket(req, socket, head, target) { |
| 269 | metrics.activeWebSockets += 1; |
| 270 | metrics.totalWebSockets += 1; |
| 271 | const finish = once(() => { |
| 272 | metrics.activeWebSockets = Math.max(0, metrics.activeWebSockets - 1); |
| 273 | }); |
| 274 | socket.on("close", finish); |
| 275 | socket.on("error", finish); |
| 276 | |
| 277 | try { |
| 278 | proxy.ws(req, socket, { target }, head).catch((err) => { |
| 279 | metrics.totalErrors += 1; |
| 280 | if (!isBenignSocketError(err)) { |
| 281 | console.error( |
| 282 | `[${label}] WebSocket proxy error for ${req.url} -> ${target}:`, |
| 283 | err, |
| 284 | ); |
| 285 | } |
| 286 | socket.destroy(); |
| 287 | finish(); |
| 288 | }); |
| 289 | } catch (err) { |
| 290 | metrics.totalErrors += 1; |
| 291 | if (!isBenignSocketError(err)) { |
| 292 | console.error( |
| 293 | `[${label}] WebSocket proxy error for ${req.url} -> ${target}:`, |
| 294 | err, |
| 295 | ); |
| 296 | } |
| 297 | socket.destroy(); |
| 298 | finish(); |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | function dumpMetrics() { |
| 303 | console.log( |
nothing calls this directly
no test coverage detected