Repository navigation
Closed
Labels
Description
Sequin database source occasionally gets stuck at an errored state with the message:
[postgres_replication_slot]: Sequin is connected, but has not received a heartbeat from the database's replication slot. Either Sequin is crashing or the replication process has stalled for some reason.
However, there is another replication slot abc_sub which is working totally fine.
> SELECT slot_name, confirmed_flush_lsn, active_pid, pg_size_pretty( pg_wal_lsn_diff(pg_current_wal_lsn(), confirmed_flush_lsn) ) AS replication_lag FROM pg_replication_slots;
+-------------+---------------------+------------+-----------------+
| slot_name | confirmed_flush_lsn | active_pid | replication_lag |
|-------------+---------------------+------------+-----------------|
| abc_sub | 1525/140003B8 | 5850 | 592 bytes |
| sequin_slot | 1514/6002A288 | 22112 | 67 GB |
+-------------+---------------------+------------+-----------------+The sequin container never exhausts the allocated CPU and RAM so it's not a resource issue either. The logs from sequin don't show any errors apart from the following -
[error] [08:05:05.719] [SlotProducer] replication connect failed: ERROR 55006 (object_in_use) replication slot "sequin_slot" is active for PID 19053 line=264 pid=<0.5680.0> file=lib/sequin/runtime/slot_producer/slot_producer.ex domain=elixir application=sequin account_id=eb2a3aa6-9b46-41d3-aafd-b89e4365db75 database_id=fdb099f9-14f6-4890-beb6-3c48ae87bdb1 replication_id=d644c92b-d398-4a30-a57c-254687e51e38
[error] [08:15:05.682] [SlotProcessorServer] Heartbeat verification failed (no messages or heartbeat received in last 10 min) line=382 pid=<0.5691.0> file=lib/sequin/runtime/slot_processor_server.ex domain=elixir application=sequin account_id=eb2a3aa6-9b46-41d3-aafd-b89e4365db75 database_id=fdb099f9-14f6-4890-beb6-3c48ae87bdb1 replication_id=d644c92b-d398-4a30-a57c-254687e51e38 heartbeat_id=ef48d2d0-c8a3-43c7-8bee-89b61807fad6
[error] [08:15:05.685] GenServer {:replication, {Sequin.Runtime.SlotProcessorServer, "d644c92b-d398-4a30-a57c-254687e51e38"}} terminating
[error] [08:25:05.716] [SlotProcessorServer] Heartbeat verification failed (no messages or heartbeat received in last 10 min) line=382 pid=<0.6350.0> file=lib/sequin/runtime/slot_processor_server.ex domain=elixir application=sequin account_id=eb2a3aa6-9b46-41d3-aafd-b89e4365db75 database_id=fdb099f9-14f6-4890-beb6-3c48ae87bdb1 replication_id=d644c92b-d398-4a30-a57c-254687e51e38 heartbeat_id=c65d7624-c33f-4faa-81c5-f05ef8675db8
[error] [08:25:05.718] GenServer {:replication, {Sequin.Runtime.SlotProcessorServer, "d644c92b-d398-4a30-a57c-254687e51e38"}} terminating
[error] [08:33:07.580] Sink consumer IDs do not match monitored sink consumer IDs.
The postgres logs just show sequin trying to re-connect -
LOG: unexpected EOF on standby connection
STATEMENT: START_REPLICATION SLOT sequin_slot LOGICAL 0/0 (proto_version '1', publication_names 'abc_pub', messages 'true')
LOG: starting logical decoding for slot "sequin_slot"
DETAIL: Streaming transactions committing after 1525/2C07F490, reading WAL from 1525/2C069230.
STATEMENT: START_REPLICATION SLOT sequin_slot LOGICAL 0/0 (proto_version '1', publication_names 'abc_pub', messages 'true')
LOG: logical decoding found consistent point at 1525/2C069230
DETAIL: Logical decoding will begin using saved snapshot.
STATEMENT: START_REPLICATION SLOT sequin_slot LOGICAL 0/0 (proto_version '1', publication_names 'abc_pub', messages 'true')
Restarting the sequin instance doesn't works either, we have to drop and re-create the slot each time. This has become a recurring issue for us.
Version: v0.14.6
Evironment: Running through docker, config is passed as an env -
sequin_config_yaml = yamlencode({
account = {
name = "abc"
}
users = [
{
email = var.SEQUIN_ADMIN_USER
password = var.SEQUIN_ADMIN_PASSWORD
}
]
databases = [
{
name = "abc-source"
username = local.sequin_source_db_credentials[0]
password = local.sequin_source_db_credentials[1]
hostname = local.sequin_source_db_host_port[0]
port = tonumber(local.sequin_source_db_host_port[1])
database = local.sequin_source_db_host_port_db[1]
ssl = true
slot = {
name = "sequin_slot"
create_if_not_exists = true
}
publication = {
name = "abc_pub"
create_if_not_exists = false
}
}
]
sinks = [
{
name = "abc-to-nats"
database = "abc-source"
status = "active"
source = {
include_schemas = ["public"]
exclude_tables = ["public.json_web_tokens"]
}
destination = {
type = "nats"
host = aws_route53_record.nats_dns_record.name
port = 4222
username = "nats"
password = random_password.nats_password.result
tls = true
}
}
]
})
Activity
dosubot commentedon May 4, 2026
Hi @mananapr! I'm Dosu and I’m helping the sequin team.
This looks like a confirmed issue that has been reported by other users as well. The root cause is a buffer deadlock in the message handling pipeline [1].
What's happening: When
SlotMessageStorebuffer fills up,MessageHandler.put_messagesblocksSlotProcessorServerwith aProcess.sleepretry loop [2]. This creates a deadlock becauseConsumerProducerneedsSlotProcessorServerto be responsive to drain the buffer, but it's sleeping. The buffer never drains, no LSN acknowledgments reach Postgres, and the replication slot grows unboundedly — other users have seen 50–100GB+ lag from the same pattern [3].Why restart doesn't help: The deadlock is architectural — restarting Sequin gives a fresh empty buffer, but if your throughput is high enough to fill the buffer again quickly, the same deadlock recurs. The accumulated WAL in PostgreSQL also doesn't go away with a Sequin restart, which is why you end up having to drop and recreate the slot.
The
object_in_useerror (ERROR 55006) happens because when the heartbeat verification fails and Sequin tries to reconnect, the old PostgreSQL connection may still be holding the slot active [4].Starting from
LOGICAL 0/0is actually intentional — Sequin filters messages client-side based on a cursor stored in Redis [5]. But when the slot has 67 GB of accumulated WAL, this means processing a massive backlog that overwhelms the buffer again.Workarounds until this is fixed:
max_memory_mbon your consumer to give more buffer headroom (note: a 0.8 safety factor is applied, so actual limit is 80% of configured)load_shedding_policy: discard_on_fullif you can tolerate dropping messages for overloaded consumers — this prevents the blocking behaviorThis appears to be a known architectural issue tracked across several related issues (#881, #872, #1004) [1]. Issue #2129 has a detailed deadlock trace and suggested fix from another user experiencing the same problem.
To reply, just mention @dosu.
Share context across your team and agents. Try Dosu.
mananapr commentedon May 4, 2026
Hi @dosu, I am running
sequinin docker, hencemax_memory_mbneed not be set and it will use all the available system memory. Going through the monitoring data, the memory utilization never goes above 30% which means it is not a memory bottlenckdosubot commentedon May 4, 2026
Good point, but the bottleneck here isn't your container/system memory — it's an internal per-consumer buffer limit (
max_memory_mb) that's separate from your Docker container's RAM allocation.Each sink consumer in Sequin has its own
max_memory_mbsetting (default: 128 MB) that controls theSlotMessageStorebuffer size [1]. The actual usable limit is further reduced: it'smax_memory_mb × 0.8 / partition_countper partition [2] [3]. So with the default 128 MB and, say, 3 partitions, each partition only gets ~34 MB of buffer space.When this internal buffer fills, the
payload_size_limit_exceedederror fires based purely onstate.payload_size_bytes + incoming > state.max_memory_bytes[4] — completely independent of how much system RAM is available. That's why your container memory never goes above 30% but replication still stalls.The deadlock then happens because
MessageHandler.put_messagesenters a blockingProcess.sleepretry loop when the buffer is full, which prevents the buffer from being drained, and the cycle repeats indefinitely [5].So increasing
max_memory_mbon your consumer (not Docker memory) would give more buffer headroom and delay the onset of the issue, though it doesn't fully fix the underlying deadlock. You can configure this per sink consumer — could you check what your currentmax_memory_mbis set to?To reply, just mention @dosu.
Docs are dead. Just use Dosu.
mananapr commentedon May 4, 2026
@dosu - It isn't set at the moment. The docs mention -
Hence it should be using the available system memory
dosubot commentedon May 4, 2026
There's an important distinction here — the system-wide
MAX_MEMORY_MBenv var and the per-consumermax_memory_mbare actually independent settings that serve different purposes [1] [2].The
MAX_MEMORY_MBenv var you're referring to controls system-wide memory governance. But each individual sink consumer has its ownmax_memory_mbfield that defaults to 128 MB [2] [3]. This per-consumer limit is what controls theSlotMessageStorebuffer size, and it is not automatically scaled up based on available system memory.So even though your Docker container has plenty of RAM available, the consumer's internal buffer is likely capped at the default 128 MB. After the 0.8 safety factor and partition division, the actual per-partition buffer could be quite small [4] [5]:
Once that small buffer fills, the deadlock kicks in regardless of how much container memory is free.
You can increase
max_memory_mbon your sink consumer through the Sequin web UI [6] or API — it's a per-consumer setting, not an env var. Bumping it significantly higher should give you more headroom. That said, it's a mitigation rather than a full fix for the underlying deadlock issue described above.To reply, just mention @dosu.
Docs are dead. Just use Dosu.
mananapr commentedon May 4, 2026
@dosu - you can find the config i am using in my first post. how would i set the buffer size for nats there? I don't find it documented in sinks page - https://sequinstream.com/docs/reference/sinks/overview
dosubot commentedon May 4, 2026
Unfortunately,
max_memory_mbis not currently supported in the YAML config. The YAML parser doesn't recognize it as a valid field, and adding it would trigger an "Unknown field" validation error [1]. Consumers created via YAML will always start with the default of 128 MB [2].To increase it, you'd need to update the consumer after creation through the Sequin web UI or API. Once your Sequin instance is up and your NATS sink is created from the YAML config, you can go into the UI and adjust the
max_memory_mbsetting on the consumer.That said — given this is a recurring issue for you, it might be worth opening a feature request to add
max_memory_mbsupport to the YAML config schema so it can be set declaratively alongside the rest of your sink configuration.To reply, just mention @dosu.
Share context across your team and agents. Try Dosu.
mananapr commentedon May 4, 2026
Hi @g14a - I noticed you raised a similar issue a while back.
Can you confirm if you had the same problem as well? If so, did you manage to fix it?
mananapr commentedon May 4, 2026
Hi @dosu - I don't see any option in the form to update this value. Nor do I see it documented in the API - how can i change it in that case?
dosubot commentedon May 4, 2026
You're right that it's not in the UI — the field exists in the backend but isn't currently exposed in the web form [1]. However, you can update it via the REST API:
The endpoint is
PATCH /api/sinks/{id_or_name}where you can use either the consumer's UUID or name (e.g.abc-to-nats) [2] [3]. The minimum value is 128 MB [4].That said, as discussed earlier, increasing the buffer is a mitigation — it delays the onset of the stalling but doesn't fully resolve the underlying deadlock issue. Given this is a recurring problem for you, I'd say the core issue here is the architectural deadlock described in #2129 that needs a fix from the maintainers.
To reply, just mention @dosu.
Docs are dead. Just use Dosu.
mananapr commentedon May 5, 2026
Hi @dosu - I don't think the diagnosis is correct. I searched my logs and
payload_size_limit_exceededwas never loggeddosubot commentedon May 5, 2026
You're right to push back — apologies for the incorrect diagnosis. If
payload_size_limit_exceedednever appears in your logs, the buffer deadlock likely isn't what's happening here.Looking at your error pattern more carefully, the most likely cause is a stale replication connection combined with a reconnection race condition:
unexpected EOF on standby connectionin your Postgres logs indicates Sequin's replication connection terminated abnormally (without a proper shutdown handshake) [1].ERROR 55006 (object_in_use)because the slot is still marked active for the old PID [2].This is a documented issue where replication connections can become stale without properly invoking the disconnect callback [4], leaving the system unable to recover. Since you're using
ssl = true, SSL connection failures are a common trigger for this — they can cause the connection to drop in a way that doesn't cleanly release the slot [1].Why restarting Sequin doesn't help: If the old PostgreSQL backend process (the one holding the slot active) doesn't get terminated, even a fresh Sequin instance will hit the same
object_in_useerror. That's why dropping and recreating the slot is the only thing that works for you.Potential workaround: You could try terminating the stale backend process in PostgreSQL when this occurs:
This should release the slot without requiring you to drop and recreate it. It's not a fix for the root cause, but it's less disruptive than slot recreation.
To reply, just mention @dosu.
Docs are dead. Just use Dosu.
mananapr commentedon May 5, 2026
Hi @dosu - I have tried doing
pg_terminate_backendbut it doesn't helps. Below are some more sequin server logs -dosubot commentedon May 5, 2026
These logs paint a clearer picture — this isn't just a stale replication connection. You're hitting Sequin's internal Postgres connection pool exhaustion, which is causing a cascading failure:
SlotSupervisor tries to start and calls
:monitor_message_storeonSlotProcessorServer(with a 120s timeout). This requiresSlotMessageStoreto finish initialization, which involves streaming all persisted messages from the database [1].The connection pool is saturated — the
client timed out because it queued and checked out the connection for longer than 15000msandconnection not available and request was dropped from queueerrors confirm this. Sequin's default self-hosted pool size is only 10 connections [2].SlotSupervisor startup fails because the database queries needed for initialization can't get connections from the exhausted pool.
The failed startup leaves the replication connection open, so when
Runtime.Starterretries every 20 seconds [3], it hitsERROR 55006because PostgreSQL still considers the slot active from the previous attempt.This creates an unrecoverable loop: each retry fails, pool stays saturated, replication connection never properly cleans up.
What to try:
Increase your connection pool size by setting the
PG_POOL_SIZEenvironment variable on your Sequin container (e.g.,PG_POOL_SIZE=50). The default of 10 is likely too low for your workload, especially during recovery/restart scenarios where initialization queries compete with health checks, metrics updates, and other operations.This won't address the root architectural issue, but it should prevent the pool starvation cascade that's making recovery impossible without slot recreation.
To reply, just mention @dosu.
Docs are dead. Just use Dosu.
mananapr commentedon May 12, 2026
Hi @dosu - I increased the
PG_POOL_SIZEto 30 and it was stable for one week but it again happened now.Below are the logs -
dosubot commentedon May 12, 2026
Thanks for the additional logs. This time the root cause is visible in the first error —
SlotProcessorServeris timing out on a GenServer.call to:restart_wal_cursor(5-second timeout):This means
SlotProcessorServerwas blocked and unable to respond whenSlotProducertried to call it. This call happens every 10 seconds [1] and queries all message store partitions to determine the safe WAL position to advance [2].Why SlotProcessorServer becomes unresponsive: It gets blocked by synchronous operations in its message handling pipeline — specifically
MessageHandler.handle_messageswhich includes database writes and theput_messagesretry loop withProcess.sleepwhen buffers approach capacity [3] [4]. Even without the explicitpayload_size_limit_exceedederror surfacing, the blocking behavior during message handling can exceed 5 seconds under load and cause this timeout.NATS publishing is also synchronous and sequential [5], so slow NATS delivery can propagate backpressure that contributes to SlotProcessorServer being blocked longer.
The cascade then is:
:monitor_message_storetimeoutERROR 55006Unfortunately this appears to be the same underlying architectural issue documented in #2129 [6] — synchronous blocking in the GenServer prevents it from being responsive under load, and process lifecycle cleanup during restarts doesn't properly release the replication slot.
Since increasing
PG_POOL_SIZEhelped temporarily but the core issue is the blocking pipeline design, the remaining options are:max_memory_mbon your consumer via the API (PATCH /api/sinks/abc-to-natswith{"max_memory_mb": 1024}) to give more buffer headroom before the blocking retry kicks inload_shedding_policy: discard_on_fullif you can tolerate occasional message drops — this prevents the blocking entirelyNeither is a real fix though. This is an architectural bug that needs code changes to remove the synchronous blocking from
SlotProcessorServer's critical path.To reply, just mention @dosu.
Docs are dead. Just use Dosu.
mananapr commentedon May 23, 2026
looks like increasing
PG_POOL_SIZEfixes itdev-sanket commentedon Jul 13, 2026
"Stalls and never recovers" is the failure mode I find most interesting — the silent kind, where the slot's still holding WAL but nothing's flowing and you don't find out until disk pressure. When it stalled, did confirmed_flush_lsn freeze entirely, or was it advancing-but-not-delivering? And how did you catch it — slot-lag alerting, or downstream noticing missing rows? Been trading notes with a few folks running self-hosted CDC about exactly this recovery gap; would value comparing if you're up for it. Contact's on my profile.