Skip to content

One un-registerable sink halts CDC for every sink on the shared replication slot, and the supervisor cannot recover #2154

Open

Description

@o6uoq

Summary

All sink consumers on a Postgres source share one replication slot. If one sink cannot register its SlotMessageStore, restart_wal_cursor!/1 raises an InvariantError, which kills SlotProcessorServer → SlotProducer → the entire SlotSupervisor. CDC stops for every sink on that slot, not just the failing one.

The failure is self-sustaining: killing the process aborts the very monitoring that would satisfy the invariant, so the restarted tree hits the same assertion. A supervisor restart cannot converge.

Version: v0.14.6, self-hosted on Kubernetes with an external Postgres.

Impact

A single-sink problem became a multi-hour outage of all CDC on that slot. Six sinks were configured, five were entirely healthy, and all six stopped.

The pod stayed 1/1 Ready throughout — liveness and readiness probes do not observe the replication supervisor — so nothing alerted on it.

The loop

Sink consumer ids and the slot id are redacted below as <sink-N> and <slot>.

Sink consumer IDs do not match monitored sink consumer IDs.
Sink consumers: ["<sink-1>", "<sink-2>", "<sink-3>",
                 "<sink-4>", "<sink-5>", "<sink-6>"].
Monitored: []

    (sequin 0.1.0) lib/sequin/runtime/slot_processor_server.ex:744:
        Sequin.Runtime.SlotProcessorServer.restart_wal_cursor!/1
    (sequin 0.1.0) lib/sequin/runtime/slot_processor_server.ex:242:
        Sequin.Runtime.SlotProcessorServer.handle_call/3
Last message (from #PID<...>): :restart_wal_cursor

Six sink consumers exist; Monitored is empty. Cascading from it:

GenServer {:replication, {Sequin.Runtime.SlotProducer, "<slot>"}} terminating
** (stop) exited in: GenServer.call({:via, :syn, {:replication,
     {Sequin.Runtime.SlotProcessorServer, "<slot>"}}}, :restart_wal_cursor, 5000)

and the supervisor failing to re-establish monitoring:

[Runtime.Supervisor] Failed to start SlotSupervisor:
  {:shutdown, {GenServer, :call, [{:via, :syn, {:replication,
    {Sequin.Runtime.SlotProcessorServer, "<slot>"}}},
    {:monitor_message_store, %Sequin.Consumers.SinkConsumer{
       id: "<sink-6>", max_memory_mb: 128,
       load_shedding_policy: :pause_on_full, status: :active, ...}}, 120000]}}

Note the failure reason is :shutdown, not :timeout — the target is already going down when the monitor call arrives. That is the race: the invariant fires before monitoring can complete, and enforcing it destroys the process that would have completed it.

Only one sink ever appeared in these monitor failures — 14 of 14 occurrences named the same one. The other five were collateral.

Why that one sink could not register

Its store could not load its persisted messages inside the hardcoded 5000 ms budget:

Failed to load messages from store for consumer <sink-6>:
  [SlotMessageStore] call timed out after 5000ms
    lib/sequin/runtime/slot_message_store.ex:216:
      SlotMessageStore.unpersisted_table_reader_batch_ids/1

That sink streams a table of pgvector embeddings — 1536 dimensions, roughly 6 KB per row — and had a backlog of about 2,000 messages persisted from a period when its Kafka destination was unavailable.

This is closely related to #2128 (put_persisted_messages bypassing max_memory_mb on startup) and #2132 (discard not persisting, so the backlog survives restarts). Note the reporter in #2128 also had max_memory_mb=128, which is the per-sink default.

Reproduction

  1. Configure several Kafka sinks on one Postgres source, i.e. sharing one slot.
  2. On one of them, accumulate a large persisted backlog by making the destination unavailable — a stopped broker is enough. Wide rows make it easier to hit.
  3. Restore the destination and restart Sequin.
  4. That one sink's store cannot rehydrate within 5000 ms → Monitored: [] → every sink on the slot stops.

Observed vs expected

Observed One unregisterable sink halts CDC for all sinks on the slot, permanently, across restarts
Expected A sink that cannot start is isolated. It reports unhealthy; the other sinks keep delivering

Notes

Three concerns, roughly in order of value:

  1. Isolation. A per-sink failure should not be a per-slot failure. That is the core bug.
  2. The invariant is unsatisfiable under its own enforcement. If Monitored can legitimately be empty mid-startup, raising is wrong; if it cannot, the raise must not destroy the monitoring path. Either way, restarting cannot currently converge.
  3. restart_wal_cursor is a 5000 ms GenServer.call while the store may be doing unbounded rehydration work. The timeout and the work are unrelated to each other.

Escape hatch, for anyone hitting this now

Nothing was recoverable from the UI — list, discard, load and monitor all time out against the jammed store, so the controls that would fix it cannot run. What worked: delete the offending sink, restart, and let config re-create it with a clean store. Cancelling the in-flight backfill first was not sufficient, and neither were two full pod restarts.

Activity

  1. dosubot commented on Sep 7, 2026

    @dosubot

    Hi @o6uoq! I'm Dosu and I'm helping the Sequin team.

    Your diagnosis is accurate — I traced the same mechanism through the code. Here's what I found confirming each piece:

    The invariant and crash path. verify_monitor_refs/1 checks that every non-disabled sink consumer ID (excluding those inserted in the last 10 minutes) appears in state.message_store_refs. When a consumer is missing, it returns {:error, Error.invariant(...)}, and restart_wal_cursor!/1 raises that error. Since handle_call(:restart_wal_cursor, ...) calls restart_wal_cursor! directly, the raise propagates through the GenServer.call and kills SlotProcessorServer.

    Why Monitored is empty. start_children/2 starts all message stores first, then the slot processor, and only after both calls monitor_message_store for each consumer. Store startup runs stream_messages_into_state/1 synchronously in handle_continue(:init, ...) — the store cannot accept calls (including set_monitor_ref) until this completes. A slow rehydration (your 2,258-row pgvector backlog) blocks the store from registering, so message_store_refs stays empty for that consumer.

    Why recovery cannot converge. SlotProducer calls update_restart_wal_cursor on a 10-second timer, which invokes restart_wal_cursor_fn → SlotProcessorServer.restart_wal_cursor/1. The invariant fires before the slow store finishes rehydrating and gets monitored. The raise kills SlotProcessorServer, and the supervisor restart races a fresh startup of the same slow store — exactly the :shutdown (not :timeout) you observed, because the target process is already going down when the monitor_message_store call arrives.

    Existing coverage. #2141 shows the same monitor_message_store / restart_wal_cursor shutdown trace from another user, but is about a different root cause (stale replication connection). #2128 and #2132 are about persisted-message rehydration bypassing max_memory_mb. None of them propose isolating per-sink startup failure from the shared invariant check, so this appears to be a distinct report.

    One detail worth noting: verify_monitor_refs does have a grace period — it filters out consumers inserted in the last 10 minutes — but that only covers newly created consumers, not existing consumers whose stores are slow to start. Extending this grace to cover "not yet monitored" stores (or converting the raise to a log + skip for unmonitored consumers) would address the convergence issue.

    To reply, just mention @dosu.


    Share context across your team and agents. Try Dosu.

    Leave Feedback Learn about sequin with Dosu Add Dosu to your team

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions