fix(server): survive stray uncaught exceptions and invalid dev-tunnel base URLs

A single uncaught exception (e.g. a Node-internal socket error) no longer
shuts the local server down; only a sustained storm does. The dev-tunnel
client now rejects non-http(s) base URLs cleanly instead of throwing an
uncaught exception in the connection handler.
This commit is contained in:
Bohdan Triapitsyn
2026-08-14 12:45:35 +03:00
parent b5c9da4ff0
commit 7cf869d5eb
5 changed files with 98 additions and 2 deletions
@@ -195,6 +195,15 @@ describe('dev tunnel end to end', () => {
expect(client.list()).toEqual([]);
});
test('rejects a non-http(s) base URL instead of crashing on first connection', async () => {
// A non-special scheme survives the `ws:` protocol assignment (WHATWG URL
// ignores it), so `new WebSocket(...)` used to throw inside the connection
// handler and take the whole process down.
const client = createDevTunnelClient({ logger: { warn: () => {} } });
await expect(client.open({ baseUrl: 'openchamber-ui://index', port: 5173 })).rejects.toThrow('must be http(s)');
expect(client.list()).toEqual([]);
});
// Not covered here: recovery after a request the dev server kills mid-flight.
// The behaviour is real (each connection tears down independently), but the
// abandoned socket makes this harness's teardown unreliable, and a flaky test