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

Function proxyWebSocket

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

Source from the content-addressed store, hash-verified

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(

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