(req, socket, head, target)
| 375 | } |
| 376 | |
| 377 | function proxyWebSocket(req, socket, head, target) { |
| 378 | metrics.activeWebSockets += 1; |
| 379 | metrics.totalWebSockets += 1; |
| 380 | const finish = once(() => { |
| 381 | metrics.activeWebSockets = Math.max(0, metrics.activeWebSockets - 1); |
| 382 | }); |
| 383 | socket.on("close", finish); |
| 384 | socket.on("error", finish); |
| 385 | |
| 386 | try { |
| 387 | proxy.ws(req, socket, { target }, head).catch((err) => { |
| 388 | metrics.totalErrors += 1; |
| 389 | if (!isBenignSocketError(err)) { |
| 390 | console.error( |
| 391 | `[${label}] WebSocket proxy error for ${req.url} -> ${target}:`, |
| 392 | err, |
| 393 | ); |
| 394 | } |
| 395 | socket.destroy(); |
| 396 | finish(); |
| 397 | }); |
| 398 | } catch (err) { |
| 399 | metrics.totalErrors += 1; |
| 400 | if (!isBenignSocketError(err)) { |
| 401 | console.error( |
| 402 | `[${label}] WebSocket proxy error for ${req.url} -> ${target}:`, |
| 403 | err, |
| 404 | ); |
| 405 | } |
| 406 | socket.destroy(); |
| 407 | finish(); |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | function dumpMetrics() { |
| 412 | console.log( |
nothing calls this directly
no test coverage detected