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

Function proxyWebSocket

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

Source from the content-addressed store, hash-verified

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(

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