Skip to content

WebHandle.close() hangs when awaited in tests #3

@Astralchemist

Description

@Astralchemist

The web test suite fire-and-forgets `handle.close()` because awaiting it deadlocks (test runner kills the worker at 5s/15s). The fix is in tests/web-ws.test.ts:

```ts
// Bun:test exits after the test completes; handle.close() can hang on
// upgraded sockets so we skip awaiting it here.
void handle.close();
```

Production isn't affected — `rig serve --web` calls `process.exit(0)` on SIGINT — but we should track down the root cause so:

  1. Tests can use the real close path
  2. Long-running embedders can hot-swap the web server without leaking sockets

Suspect: `WebSocketServer.close()` waits indefinitely for an upgraded socket that the test's `ws.terminate()` already destroyed, OR Fastify's `app.close()` won't return because the `http.Server` still has a registered upgrade listener.

Possible fixes:

  • Close in different order (Fastify first, ws second)
  • Call `server.closeAllConnections()` before `app.close()` (Node 18.2+ API)
  • Use a close timeout that escalates to `server.destroy()`

Repro:
```ts
const handle = await serveWeb({ projectRoot: '/tmp/x', port: 7490 });
const ws = new WebSocket('ws://127.0.0.1:7490/ws');
await new Promise(res => ws.on('open', res));
ws.terminate();
await handle.close(); // hangs
```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions