ulo
ulo
Documentation

Start here

Coming from NestJSNestJS topics, mapped

The model

Protocols

WebSocketGatewaysMessage handlers with DIRooms and broadcastRedis broadcastSeparate portLimits and shutdown

Integrations

Operating

Reference

WebSocket

Limits and shutdown

Message and connection limits, close codes, keep-alive and how a WebSocket server drains.

Limits

Each limit is set on the gateway attribute and defaulted by WsModule (gateways on the HTTP port) or by ulo_ws_hyper::Server (gateways on its own port). A key left out of the attribute takes that default.

SettingScopeDefaultOver the limit
max_messagebytes per message after reassembly64 MiBthe connection closes with 1009
max_connectionsper gatewaynonethe connection is accepted, then closed with 1013 unavailable: too many connections; under refuse = handshake the upgrade is refused 503 with Retry-After
max_inflightmessages queued or running per connection64the gateway stops reading from that connection
server_max_inflightmessages in flight across all connections of the server1,024every connection stops reading while no place is free
max_outboundqueued outgoing messages per connection1,024closes with 1008 slow consumer, or drops the oldest with overflow = drop_oldest
ping_intervalkeep-alive Ping period30 secondsBound::Unbounded sends none
pong_timeouttime for a Pong30 secondsthe connection ends as Lost

max_message counts bytes per message; tungstenite also caps a frame at 16 MiB. Count::Max(0), a zero max_message and a zero Bound::After are refused in prepare, with the HTTP server's hint to write Unlimited or Unbounded instead.

max_inflight and server_max_inflight apply backpressure rather than refusing: the TCP connection carries it to the client. Answers to different messages, a stream's items among them, may interleave, each carrying its message's id. Only unary answers under a bound of one come back in the order their messages arrived.

server_max_inflight has no form on the gateway attribute. It is set on WsModule::server_max_inflight or ulo_ws_hyper::Server::server_max_inflight.

A connection turned away for capacity runs no connect hook and no on_disconnect.

Close codes

CodeWhen
1001the server is shutting down (the server is shutting down)
1002a protocol violation
1003a binary frame on a text-only gateway
1007a text frame that is not UTF-8
1008BadRequest, NotFound, Conflict or Unprocessable at connect, and a slow consumer
1009a message over max_message
1011Internal or Unimplemented at connect, including a panic in OnConnect, and a panic in a hand-written gateway's on_message
1013TooManyRequests or Unavailable at connect, and a gateway over max_connections
3000Unauthorized at connect
3003Forbidden at connect, a connect guard's Ok(false) included
3008Timeout at connect
3000 to 4999codes a gateway sets itself through ConnectRefused::code(CloseCode, reason) or CallError::with_close_code(CloseCode), as graphql-transport-ws does with 4401

A refusal by kind under 1008, 1011 or 1013 starts its reason with the kind as the envelope spells it, then : : not_found: no such room, unavailable: too many connections, internal: internal error. A client reads the kind back from the reason. A code one kind owns (3000, 3003, 3008) carries the reason alone.

Frames Ping, Pong and Close are handled by the protocol layer. A client that offers permessage-deflate is answered without it, since tungstenite has no RFC 7692 support, and messages travel uncompressed.

Keep-alive

The server sends a Ping every ping_interval. A Pong that misses pong_timeout, or a connection closed without a Close frame, ends the connection as DisconnectReason::Lost.

Shutdown

At the start of the drain, idle connections close with 1001 at once. Busy connections stop reading, finish their in-flight messages, then close with 1001. Each of these connections gets on_disconnect with DisconnectReason::Drain.

After sending 1001, the read loop waits for the client's Close under pong_timeout, and the app's drain window (AppBuilder::drain_timeout, ten seconds unset) ends the wait first if it is shorter. A client that never answers delays shutdown by the shorter of the two.

An upgrade request arriving once the drain has begun is refused 503. A connection admitted during the 101 but caught by the drain before its connect phase opened is refused with the drain's own 1001 and runs no hook.

examples/23-ws-gateway pins the close frame: a drain delivers (1001, "the server is shutting down") to an idle connection, and the journal then reads disconnected ada: Drain.

Both servers (the HTTP hand-off and ulo-ws-hyper) run the same drain, through the gateway table's drain and close. On the HTTP port the hand-off's drain and close are driven by the HTTP server's, since an upgraded connection has left the HTTP engine.

Separate port

Serving a gateway on its own port with ulo-ws-hyper, and choosing between that and the HTTP server's port.

Overview

RPC between services over TCP, UDP, NATS, Redis, MQTT, RabbitMQ or Kafka, with one set of handlers and one wire grammar.

On this page

LimitsClose codesKeep-aliveShutdown