[websocket]
WebSocket routes (route.ts files that export wsHandler): the switch, the connection cap and server pings.
gio.toml
[websocket]
max_connections = 5000
ping_interval_secs = 25The Origin check on upgrades lives in [security.websocket]. The WebSockets guide covers handlers, rooms and the client.
Reference
| Key | Default | Description |
|---|---|---|
enabledboolean | true | Accept WebSocket upgrades and connect them to the worker's wsHandlers. Off, no socket is ever opened. The origin check still runs first, so a cross-site upgrade gets its 403 instead. |
max_connectionsinteger | 1000 | Open WebSockets across the server. A socket over the cap is accepted and immediately closed with 1013 (try again later), reason too many connections, which clients read as a reason to back off and retry. |
ping_interval_secsinteger | 30 | Ping every socket this often, so a peer that vanished is noticed when the ping cannot be sent and the socket is closed. The first ping goes out one interval after the connection opens. |
Behavior
- Open sockets are not counted by
[server] max_connections, and the connection timeouts in[server]never close them. - A path whose module exports no
wsHandlercloses the socket with4404; an async handler whose promise rejects closes it with1011. See Close codes. - If the server cannot connect to the worker's WebSocket channel at startup, it logs
WS IPC connect failed - WebSocket disabledand answers upgrades501as ifenabledwerefalse.
Startup warnings
| When | Startup warning |
|---|---|
max_connections = 0 while enabled | [websocket] max_connections = 0: WebSocket connections are unlimited - every open socket holds memory and a file descriptor |
Examples
No WebSockets
gio.toml
[websocket]
enabled = falseBehind a proxy with a 60-second idle timeout
Pings keep the connection busy, so the proxy does not close a quiet socket:
gio.toml
[websocket]
ping_interval_secs = 25Good to know
0means unlimited formax_connectionsand no pings forping_interval_secs. To refuse WebSockets, useenabled = false.- Each open socket holds a file descriptor: keep the process limit (
ulimit -n) above[server] max_connectionsplus this cap. - In a worker pool each socket stays on one worker; room broadcasts reach sockets on every worker.
Related
Version history
| Version | Changes |
|---|---|
v0.1.0-beta.8 | max_connections = 0 means unlimited (it closed every socket with 1013) and logs a startup warning; ping_interval_secs = 0 means no pings (it crashed every connection). |
v0.1.0-beta.1 | Introduced with enabled, max_connections and ping_interval_secs. |