(req, socket, head, target)
| 111 | } |
| 112 | |
| 113 | function proxyWebSocket(req, socket, head, target) { |
| 114 | metrics.activeWebSockets += 1; |
| 115 | metrics.totalWebSockets += 1; |
| 116 | const finish = once(() => { |
| 117 | metrics.activeWebSockets = Math.max(0, metrics.activeWebSockets - 1); |
| 118 | }); |
| 119 | socket.on("close", finish); |
| 120 | socket.on("error", finish); |
| 121 | |
| 122 | try { |
| 123 | proxy.ws(req, socket, { target }, head).catch((err) => { |
| 124 | metrics.totalErrors += 1; |
| 125 | if (!isBenignSocketError(err)) { |
| 126 | console.error( |
| 127 | `[${label}] WebSocket proxy error for ${req.url} -> ${target}:`, |
| 128 | err, |
| 129 | ); |
| 130 | } |
| 131 | socket.destroy(); |
| 132 | finish(); |
| 133 | }); |
| 134 | } catch (err) { |
| 135 | metrics.totalErrors += 1; |
| 136 | if (!isBenignSocketError(err)) { |
| 137 | console.error( |
| 138 | `[${label}] WebSocket proxy error for ${req.url} -> ${target}:`, |
| 139 | err, |
| 140 | ); |
| 141 | } |
| 142 | socket.destroy(); |
| 143 | finish(); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | function dumpMetrics() { |
| 148 | console.log( |
nothing calls this directly
no test coverage detected