Skip to content

Commit 97d2259

Browse files
committed
hub-proxy: close when receive error event
1 parent 220c73d commit 97d2259

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/packages/hub/proxy/handle-upgrade.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export default function init(
109109
proxy.on("error", (err) => {
110110
logger.debug(`websocket proxy error, so clearing cache -- ${err}`);
111111
cache.delete(target);
112+
proxy.close();
112113
});
113114
proxy.on("close", () => {
114115
dbg("websocket proxy closed, so removing from cache");

src/packages/hub/proxy/target.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@ const logger = getLogger("proxy:target");
2828
// Also, if the project stops and starts, the host=ip address could
2929
// change, so we need to timeout so we see that thange.
3030

31-
const cache = new LRU({ max: 20000, ttl: 1000 * 30 });
31+
const cache = new LRU<
32+
string,
33+
{
34+
host: string;
35+
port: number;
36+
internal_url: string | undefined;
37+
}
38+
>({ max: 20000, ttl: 1000 * 30 });
3239

3340
// This gets explicitly called from outside when certain errors occur.
3441
export function invalidateTargetCache(remember_me: string, url: string): void {

src/packages/hub/servers/nats.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export async function proxyNatsWebsocket(req, socket, head) {
3838
timeout: 5000,
3939
});
4040
proxy.ws(req, socket, head);
41+
proxy.on("error", (err) => {
42+
logger.debug(`nats websocket proxy error, so closing -- ${err}`);
43+
proxy.close();
44+
});
4145

4246
while (socket.readyState !== socket.CLOSED) {
4347
if (versionCheckFails(req)) {

0 commit comments

Comments
 (0)