# Troubleshooting realtime
Source: https://sovaria.in/docs/troubleshooting-realtime

Connections that close (4401, 4408, 1013), messages or database change events that don't arrive, gaps after reconnecting, and presence that looks wrong.

## The connection closes with 4401, 4408 or 1013

- **Cause:** `4401`: the ticket was bad, expired or reused, or the user signed out. `4408`: a rule or limit refused the connection or a message (size, events per second). `1013`: the client didn't read fast enough.
- **Check:** The close code in your `onStatus`/`onError` handler; the channel's rules; Realtime › Settings for limits.
- **Fix:** Let the SDK fetch a new ticket; allow `SUBSCRIBE` for the channel; keep messages small; handle messages faster ([Channels and connections](https://sovaria.in/docs/realtime-channels)).
- **Verify:** The status reaches `live` and stays there.

## Published messages don't arrive

- **Cause:** The publisher isn't allowed to `PUBLISH`, the channel names differ, or the receiver connected after the message was sent.
- **Check:** The publish call's response (a refusal is an error there) and the exact channel names on both sides.
- **Fix:** Allow `PUBLISH` for the sender; after reconnecting, catch up with replay from the last `stream_seq` you saw.
- **Verify:** Both sides see the same messages, in order.

## Database change events don't arrive

- **Cause:** Change capture isn't on for that table, the write went through a direct Postgres connection, the statement changed no rows, or the listener may not subscribe to `db.table.<table>`.
- **Check:** Realtime › Database change data capture; how the write was made.
- **Fix:** Turn capture on for the table and allow `SUBSCRIBE` on its channel ([Database change events](https://sovaria.in/docs/realtime-database-changes)).
- **Verify:** Insert a row through the API; an event with `row_count: 1` arrives.

## subscribe() reports CHANNEL_ERROR (or showed SUBSCRIBED, then CHANNEL_ERROR)

- **Cause:** No channel rule lets this user subscribe, or they aren't signed in. Before JS SDK 0.10.5 and Python 0.12.3 a refused channel briefly showed `SUBSCRIBED` first; newer SDKs wait for the server to admit the join.
- **Check:** The error passed to the `subscribe` callback, and your channel rules for `SUBSCRIBE` on that name ([Channels and connections](https://sovaria.in/docs/realtime-channels)).
- **Fix:** Add a channel rule for that user or role; update the SDK so `SUBSCRIBED` means admitted.
- **Verify:** The callback gets `SUBSCRIBED` once, and other users still get `CHANNEL_ERROR`.

## Presence shows people who left, or one person several times

- **Cause:** A connection that vanished without closing stays listed for about 90 seconds; each tab or device is its own connection.
- **Check:** How many tabs or devices the person has open.
- **Fix:** Close connections when a page is left (`channel.close()`); group presence by user id in your app ([Presence](https://sovaria.in/docs/realtime-presence)).
- **Verify:** After closing a tab, it disappears from presence at once.

## Someone on an older SDK is missing from presence, or stays listed after leaving

- **Cause:** Older SDKs (JavaScript up to 0.9.2 with `broadcast.ack`, Python up to 0.11.2) send `track` through the publish API. That presence is kept only for signed-in users with the channel's SUBSCRIBE rule, at most 10 per user per channel, and stays 90 seconds after the last `track` unless the client untracks.
- **Check:** The publish answer: a `presence_refused` field says why the presence wasn't kept.
- **Fix:** Update the SDK (presence then rides on the connection), or sign the user in and add a SUBSCRIBE rule for the channel ([Broadcast, presence and table changes](https://sovaria.in/docs/realtime-broadcast-and-presence)).
- **Verify:** A client that joins later sees the person in `presenceState()` at once.

## Still stuck?

Email [outreach@sovaria.in](mailto:outreach@sovaria.in) with your project URL, the time it happened (with time zone), the `X-Request-ID` response header or the `trace_id` from the error body, and the channel name and the close code. Never send keys, passwords, tokens or your users' data.
