MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / proxyWebSocket

Function proxyWebSocket

scripts/proxy-utils.mjs:268–300  ·  view source on GitHub ↗
(req, socket, head, target)

Source from the content-addressed store, hash-verified

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(

Callers

nothing calls this directly

Calls 4

onceFunction · 0.85
isBenignSocketErrorFunction · 0.85
errorMethod · 0.80
finishFunction · 0.70

Tested by

no test coverage detected