Troubleshooting
Most answers are in Cabby's log. Many of the lines below are debug lines: start Cabby with
--debug (or CABBY_DEBUG=true) to see them.
Connections
The WebSocket fails behind a proxy
The browser reports a failed connection, and Cabby answered 400 Bad Request. With --debug:
DBG WebSocket connection upgrade failed context=ws error="websocket: the client is not using the websocket protocol: 'upgrade' token not found in 'Connection' header"
The proxy dropped the Upgrade or Connection header. Configure it to pass both on, over
HTTP/1.1: Deploying Cabby has Caddy and Nginx examples. curl shows the same answer
when you call Cabby directly without the headers, which tells you whether the proxy or Cabby is
in the way.
A proxy that speaks HTTP/1.0 to Cabby, as Nginx does without proxy_http_version 1.1, gets 400
too:
DBG WebSocket connection upgrade failed context=ws error="websocket: the client is not using the websocket protocol: HTTP version is not 1.1"
403 Forbidden
DBG WebSocket connection upgrade failed context=ws error="websocket: request origin not allowed by Upgrader.CheckOrigin"
The page's origin isn't in --allowed_origins. An entry such as app.example.com matches that
host on any scheme, *.example.com its subdomains, and a full origin such as
https://app.example.com only that scheme and port; Configuration has the
details. An entry that can never match is ignored, and Cabby says so at startup:
WRN allowed_origins entry "https://app.example.com/path" never matches and is ignored: it has a path, query or fragment. Fix or remove the entry to silence this warning context=config
SSE and Durable Streams use the same list for their CORS headers.
Every origin allowed
WRN allowed_origins allows every origin: pages on any site can open WebSocket connections in a user's browser, with the user's cookies. Set allowed_origins (--allowed_origins, CABBY_ALLOWED_ORIGINS) to your application's origins to silence this warning context=config
--allowed_origins is empty, the default, or has *. A browser sends the user's cookies with a
WebSocket connection whatever page opens it, so if your app authenticates connections with
cookies, a page on another site could connect as that user. Set --allowed_origins to your app's
origins.
Connected, then "unauthorized"
The client gets {"type":"disconnect","reason":"unauthorized","reconnect":false} and the
connection closes with Auth Failed. Either your app's connect rejected it, or nothing could
identify the client:
- With
--norpc, connections need a JWT or--noauth. - A JWT signed with another key, or
--enforce_jwtwithout a token, gives this answer; an expired token gives"reason":"token_expired"instead. - Cookies only reach
connectif the browser sends them to Cabby's host: set the cookie's domain so the WebSocket's host receives it.
Authentication covers each case.
No welcome at all
The connection opens, nothing comes, and about 3 seconds later it closes with Auth Error. Cabby
can't reach your app over RPC, and logs:
ERR WebSocket session failed error="failed to authenticate, cause: synthetic.wrap: retry interrupted, cause: context deadline exceeded (hidden: rpc error: code = Unavailable desc = Post \"http://localhost:3000/_cabby/connect\": dial tcp localhost:3000: connect: connection refused)"
Check --rpc_host from where Cabby runs: inside a container, localhost is the container itself.
Too many open files
Every connection needs a file descriptor. Past the limit, Cabby can't accept new connections while
the existing ones carry on, and with --debug Cabby logs accept failed with the system's error. The startup
line shows the limit Cabby got, open file limit: 1024 for example. Raise it as
Deploying Cabby shows.
Broadcasts
401 from /_broadcast
The request's key doesn't match. The Authorization: Bearer header must carry the broadcast key:
--broadcast_key, or the key Cabby derives from --secret (Authentication).
Usually the app and Cabby have different secrets.
404 from /_broadcast
The request went to the wrong port. With a secret or a broadcast key, Cabby takes broadcasts on its
main port, unless --http_broadcast_port gives them their own; without either, on port 8090. The
startup log says where:
WRN Accept broadcast requests at http://localhost:8090/_broadcast (no authorization): anyone who can reach it can broadcast to any stream and disconnect clients; set --broadcast_key or --secret to require authorization context=broadcast provider=http
Without a key the line is a warning, since anyone who can reach the port can broadcast. With one,
it's an info line ending in (authorization required).
Cabby stops: --api_secret is none
--api_secret is "none": the API would take requests without authorization. Set a secret for it (or --secret), or remove the setting
none turns most keys off, but an API without a key would take every request, so Cabby refuses
it. Set a real --api_secret, or remove the setting to use the key derived from --secret
(Configuration).
201, but nobody receives it
-
The stream name differs. The broadcast's
streammust be exactly the stream the client subscribed to: the name inside the signed stream, or what your channel'sstream_fromchose. -
The body isn't what Cabby expects. Cabby still answers
201, counts it infailed_broadcast_msg_totaland logs:WRN failed to parse pubsub message context=node data="stream=a" error="invalid character 's' looking for beginning of value"Send JSON, as in Run it:
{"stream":"room:1","data":"{\"text\":\"Hello\"}"}. -
The app broadcasts through Redis, Cabby listens over HTTP. The two adapters have to match. With a Redis URL and HTTP-only broadcasts, Cabby warns at startup:
WRN Redis is configured but broadcasts are HTTP only; set CABBY_BROADCAST_ADAPTER to add redis or redisx context=configThe Docker image takes broadcasts over HTTP only unless you set
CABBY_BROADCAST_ADAPTER. -
One node's clients get it late or not at all, after a network blip. That node lost its pub/sub connection: its log has
Redis pub/sub disconnected, thenreconnected(Redis), orconnection failed, thenconnection restored(NATS);postgres_errors_totalcounts lostLISTENconnections. With the Redis, PostgreSQL or NATS broker, the node delivers the missed messages once it's back, and logs a warning if some had already left the history, or an error if it couldn't read them. The in-memory and SQLite brokers keep no shared history, so those messages are lost: use a shared broker (Several nodes). -
The page was offline when it was sent.
@rails/actioncable, and Turbo's own connection, don't get missed broadcasts back.@cabby/webdoes, with a broker, and so do Turbo Streams afterbin/rails g cabby:client(Hotwire).
Subscriptions are rejected
The client gets reject_subscription. With --debug, subscription failed says why:
error= |
Cause |
|---|---|
"verification failed" |
The stream was signed with another secret than Cabby's --streams_secret (or --secret) |
"invalid identifier, cause: public streams are not allowed" |
An unsigned stream_name without --public_streams |
"invalid identifier, cause: public streams can't use the names of authorized Pusher channels" |
An unsigned name starting with private- or presence- while the Pusher endpoint is on: those channels need a signature. Sign the name |
For Turbo Streams with --turbo_streams, the key Rails signs with must be Cabby's
(Hotwire).
Redis
Cabby can't reach Redis
The default broadcast adapters, http,redis, read from Redis. Without it, Cabby keeps running and
retries:
ERR failed to connect to Redis context=pubsub error="Connection refused (os error 61)"
INF next Redis reconnect attempt in 250ms context=pubsub
If you don't run Redis, set --broadcast_adapter=http (CABBY_BROADCAST_ADAPTER=http). If you
do, check --redis_url (also REDIS_URL). With Redis pub/sub, what Cabby publishes meanwhile is
dropped: the log says failed to connect to Redis once, then Redis publishing restored with
dropped=<n>. The Redis broker is stricter: it stops Cabby
at startup when Redis is unreachable.
TLS
With a rediss:// URL, Cabby checks the Redis server's certificate. When it doesn't pass, Redis
pub/sub and the Redis broadcast adapters log it on every connection attempt and keep retrying:
ERR failed to connect to Redis context=pubsub error="invalid peer certificate: UnknownIssuer"
With the Redis broker, Cabby stops at startup:
failed to start broker, cause: failed to start the Redis broker, cause: invalid peer certificate: UnknownIssuer
UnknownIssuer: no CA Cabby trusts signed the certificate. If your provider signs with its own, name its certificate file in--redis_tls_ca_cert_path.certificate not valid for name "10.0.0.5"; certificate is only valid for DnsName("redis.internal"): the host in the URL isn't on the certificate. Connect by a name it carries (rediss://redis.internal:6380). With Sentinel, the master's certificate has to be valid for the address the Sentinel gives or for the host of the first--redis_sentinelsaddress.Redis Cluster node 10.0.0.7:6380: ...; its certificate must be valid for 10.0.0.7, the address the node announces: a cluster node's certificate has to carry the address the node announces, its IP address unless the cluster announces host names (Redis).
On a network you trust, --redis_tls_verify=false turns the check off, and Cabby says so at
startup:
WRN Redis server TLS certificate is not verified; set --redis_tls_verify=true to enable verification
--redis_tls_client_cert_path and --redis_tls_client_key_path add a client certificate. A
rediss:// URL needs a Redis that speaks TLS; for Sentinel, see Redis.
Broadcasts fail with NOPERM
With the Redis broker and a Redis ACL, a broadcast fails, and the error has
NOPERM this user has no permissions to publish on the channel. The broker publishes what it
stores: give its user +publish and the streams' channels (&*, or &<prefix>:* with a channel
prefix), as Redis shows.
Clients get another app's messages
Clients receive broadcasts that belong to another app, or to another environment of the same app: the two share a Redis. Broadcasts travel over Redis pub/sub, which a key prefix or another database number doesn't divide, so a broadcast reaches the clients of every Cabby on that Redis that subscribe to a stream of the same name. A key prefix alone doesn't separate them. Give each app and each environment its own Redis, or, on a shared one, its own channel prefix, key prefix and broadcast stream (Two apps on one Redis).
PostgreSQL
Cabby stops: column epoch is missing
failed to start broker, cause: failed to start Postgres broker, cause: column epoch of table public.cabby_streams is missing: run ALTER TABLE "public"."cabby_streams" ADD COLUMN epoch TEXT or set --postgres_auto_migrate=true
Cabby 0.6 keeps each stream's epoch in a column that 0.5 didn't have, and with
--postgres_auto_migrate=false it doesn't add it. Run the statement from the message, with your
schema and table prefix, and start again (PostgreSQL).
Positions unknown after the upgrade
After an upgrade to 0.6, reconnecting clients get reject_history and
rejected_history_requests_total rises: nodes of 0.5 and 0.6 are running side by side. A stream
first written by an upgraded node then has two epochs, and a client whose last message came
through the other kind of node is told its position is unknown. Finish restarting every node
(Upgrading to 0.6).
NATS
Cabby exits: attempts exceeded
Cabby lost NATS, and exits with status 1 once its attempts in a row run out. The log has
failed to reconnect to NATS: attempts exceeded. max_reconnect_attempts under [nats] in the
configuration file sets a limit, and a file written by --print-config of Cabby 0.5 holds
max_reconnect_attempts = 5. Remove the line, or set it to -1, and Cabby keeps trying for as
long as NATS is away (NATS).
JetStream lines in the log
With the NATS broker, these warnings say that a node is repairing its copy of a stream's history:
JetStream consumer failed, creating it again: NATS deleted the consumer the node copies the stream with, after a link that stalled or a connection that stayed lost. The node makes it again from where its copy stopped, and until then rejects history requests for the stream (reject_history) rather than answer without the latest messages.JetStream stream is gone, creating it again: NATS lost its JetStream data, for example a restart without its store. The node makes the stream again and sends the broadcast once more. The nodes get a new epoch, offsets start again at 1, and clients holding older positions resync.JetStream stream was made again, copying it from its start: the stream was made again, and the node copies it from its first message.
A client whose history request is rejected loads the current state again
(When catching up fails). A broadcast NATS can't
store answers 501, and the log has failed to add message to JetStream stream.
History and presence
- A client gets a new session after reconnecting: a session is restored once, and only after it
has gone. The client sent an id that has already restored a session, or the id of a session
still connected, or one that expired (
--sessions_ttl). Your app'sconnectruns, and history requests still bring back what it missed. A client of your own should send the id of the latestwelcome(History, recovery and presence). - Turbo pages, or a channel without
whisper: true, stopped receiving whispers: a whisper reaches only the subscriptions that take whispers on its stream. Open the stream withwhisper: truein the channel that reads them (Whispers). During a node-by-node upgrade, the clients of 0.5 nodes miss the whispers sent through 0.6 nodes until those run with--whisper_compat_0_5. reject_history: there is no broker (couldn't retrieve historywitherror="history not supported"), the stream's epoch changed, or the client's last message has left the stream's history (failed to handle incoming messagewitherror="stream is empty"orrequested offset couldn't be found). The client has to load the current state again (When catching up fails).couldn't retrieve historywitherror="history not supported"at every page load: your pages carrysince(Hotwire) and Cabby has no broker, so it refuses each page's first request and logs this warning once per subscribe. Live broadcasts still arrive. Add a broker (--presets=broker), or turnturbo_streams_sinceoff.- Several nodes, and a client misses messages or starts a new session: with the in-memory or SQLite broker, each node keeps only what it accepted, so history can succeed without the messages that went through another node. Use a shared broker (Several nodes).
"type":"error"for presence: the broker has no presence (none, PostgreSQL or NATS), and Cabby logspresence not supported. With the Redis broker, Redis didn't answer: the log has the broker's error.- Several nodes, and a member is announced twice, is missing from the list, or gets a
leavewhile still connected: the in-memory and SQLite brokers keep presence per node, and each node announces its own joins and leaves. The Redis broker keeps one list for every node. - A client's
joinorleavechanges nothing: your app joined that subscription to presence from its channel, so the app sets it, and the client gets no reply. Cabby logs a warning, no--debugneeded:failed to handle incoming messagewitherror="presence is set by the application for identifier: ...; join and leave from the channel's callbacks and actions instead". Join and leave in the channel's callbacks and actions instead, withjoin_presenceandleave_presencein Rails (Rails).
History, recovery and presence explains both.