Bug #78408
closedDaemonServer::ms_handle_reset() never releases daemon_connections refs for non-OSD peers — unbounded AsyncConnection leak
0%
Description
ceph-mgr RSS grows linearly and indefinitely until it is OOMKilled (or manually restarted), independent of cluster load or client activity. Heap profiling attributes ~92% of the growth to AsyncConnection objects allocated in AsyncMessenger::add_accept() that are never freed. The growth is driven by a constant stream of short-lived internal connections (standby mgr + the mgr's own client), each accepted, made READY, then closed by the peer within ~200-250 ms.
Symptom
mgr RSS climbs at a steady rate (~1.5 MiB/hr steady-state in a minikube repro; ~24-55 MiB/day observed across two environments), unrelated to workload.
Eventually the mgr hits its memory limit and is restarted; memory resets, then climbs again from the new baseline.
Core storage (OSD/MON/client I/O) is unaffected.
Root cause (evidence)
1. tcmalloc heap profile (pprof --cum, diff of two dumps ~90 min apart):
~92% of heap growth is in:
operator new
└ AsyncConnection::AsyncConnection
└ AsyncMessenger::add_accept
└ Processor::accept
└ EventCenter::process_events
2. Perf counters (ceph tell mgr.X perf dump AsyncMessenger::Worker-*):
- msgr_created_connections climbs continuously (e.g. 977 → 1286+ on one worker).
- msgr_active_connections stays flat (~12).
- One worker (Worker-0) shows the vast majority of created connections (977 vs ~60 on others).
3. File descriptors: flat (~55) throughout → this is a C++ object leak, not a socket/FD leak.
4. debug_ms=1 capture (2-3 min window): 41 connections, perfectly balanced lifecycle — accept: 41, ready: 41, stop: 41, peer close: 41:
conn(...).accept
conn(...)._handle_peer_banner_payload supported=3 required=0
conn(...).ready entity=client.<N> ... l=1 # LOSSY
conn(...).read_bulk peer close file descriptor 49
conn(...).read_until read failed
conn(...).stop
- All connections are lossy (l=1) internal clients.
- global_id (client.<N>) increments rapidly (~+6 in 2 s) → constant re-authentication/churn.
- Rate ≈ 14-20 connections/min, sustained.
5. Churn is internal (not client-driven): identical churn with and without the Rook toolbox / external clients connected. Sources are the standby mgr and the mgr's own client connection.
6. Retention (inferred, not yet directly proven): Because msgr_active_connections (the registered conns map) stays flat while created climbs and memory grows, the leaked AsyncConnection objects are not in conns. They are retained in one of accepting_conns / anon_conns / deleted_conns (reap queue not draining) — i.e. accepted lossy connections are stop()-ped at the protocol layer but the AsyncConnection object is not reaped/freed.
Reproduction
- Deploy Ceph 20.2.0 (2 mgr daemons; Rook 1.18.10).
- Let it idle — no client workload required.
- Watch msgr_created_connections climb steadily while msgr_active_connections stays flat:
# ceph tell mgr.<active> perf dump | grep -A3 msgr_ #- Sample mgr RSS over hours → linear growth.
- Optional: ceph tell mgr.<active> config set debug_ms 1 → observe ~14-20/min lossy l=1 internal connections doing accept → ready → peer-close → stop.
Impact
Every cluster is affected (churn is internal, independent of external clients).
mgr is periodically OOMKilled; on single-mgr clusters this is a transient mgr availability gap.
- Additional info available on request
- tcmalloc .heap dumps (pre/post) and pprof --cum output.
- Full debug_ms=1 capture.
- Per-worker perf dump.
SS Updated by sunnat samad 5 months ago
ceph-mgr RSS grows linearly and indefinitely until it is OOMKilled (or manually restarted), independent of cluster load or client activity. Steady-state heap profiling attributes ~95% of the growth to memory allocated in AsyncConnection::AsyncConnection via AsyncMessenger::add_accept(). The connections themselves are reaped by the messenger, but their construction memory is never freed — indicating a retained reference (or un-freed constructor allocation) outside the messenger. The growth is driven by a constant stream of short-lived internal connections (standby mgr + the mgr's own client), each accepted, made READY, then closed by the peer within ~200-250 ms.
Environment
- Ceph 20.2.0 (Tentacle), deployed via Rook 1.18.10
- Allocator: tcmalloc (gperftools)
- Also observed: Ceph 19.2.3 (Squid)
Symptom
mgr RSS climbs at a steady rate (~1.5 MiB/hr RSS in a minikube repro; ~24-55 MiB/day observed across two environments), unrelated to workload.
Eventually the mgr hits its memory limit and is restarted; memory resets, then climbs again from the new baseline.
Core storage (OSD/MON/client I/O) is unaffected.
Root cause (evidence)
1. tcmalloc steady-state heap diffs (post-warmup, same mgr process, restartCount=0, 30-min HEAPPROFILE auto-dumps):
Span Net growth Dominant stack
1.5 h +0.8 MB ~93% under the stack below
3.0 h +2.0 MB ~95-96% under the stack below
Growth scales with time and the same site dominates across independent spans → steady linear leak (~0.6-0.7 MB/hr sampled), not sampling noise.
2. Perf counters (ceph tell mgr.X perf dump AsyncMessenger::Worker-*):
msgr_created_connections climbs continuously (e.g. 977 → 1286+ on one worker).
msgr_active_connections stays flat (~12).
One worker (Worker-0) shows the vast majority of created connections (977 vs ~60 on others).
3. File descriptors: flat (~55) throughout → C++ object/allocation leak, not a socket/FD leak.
4. debug_ms=1 capture (2-3 min window): 41 connections, perfectly balanced lifecycle — accept: 41, ready: 41, stop: 41, peer close: 41:
All connections are lossy (l=1) internal clients.
global_id (client.<N>) increments rapidly (~+6 in 2 s) → constant re-authentication/churn.
Rate ≈ 14-20 connections/min, sustained.
5. Churn is internal (not client-driven): identical churn with and without the Rook toolbox / external clients connected. Sources are the standby mgr and the mgr's own client connection.
6. Retention mechanism (corrected): The messenger does reap these connections. debug_ms=5 tracing shows reap_dead runs regularly and reap_dead delete <AsyncConnection*> fires for essentially all accepted connections (3-min window: 28 accepted → 24 reaped → 4 just-pending the next reap pass). So the objects are not stuck in accepting_conns/deleted_conns.
However, the AsyncConnection construction memory is not freed despite reaping (net linear growth at AsyncConnection::AsyncConnection persists across both heap diffs above). AsyncConnection is refcounted; if its refcount reached 0 on reap, the destructor would free recv_buf and members. It does not → a ConnectionRef is retained outside the messenger (or a constructor sub-allocation such as recv_buf is not freed), keeping each churned lossy connection's memory alive after reap_dead. The specific owner of the retained reference is not yet identified (requires debuginfo+gdb or source review of where the mgr stores ConnectionRefs on ms_handle_accept).
Reproduction
Deploy Ceph 20.2.0 (2 mgr daemons; Rook 1.18.10).
Let it idle — no client workload required.
Watch msgr_created_connections climb steadily while msgr_active_connections stays flat:
Sample mgr RSS over hours → linear growth. Or diff two steady-state tcmalloc heap dumps and observe net growth under AsyncMessenger::add_accept → AsyncConnection::AsyncConnection.
Optional: ceph tell mgr.<active> config set debug_ms 1 → observe ~14-20/min lossy l=1 internal connections doing accept → ready → peer-close → stop.
Impact
Every cluster is affected (churn is internal, independent of external clients).
mgr is periodically OOMKilled over long uptimes (timescale: weeks at ~16 MB/day); on single-mgr clusters this is a transient mgr availability gap.
SS Updated by sunnat samad 5 months ago
- Subject changed from mgr: AsyncConnection objects leak from AsyncMessenger::add_accept on churned short-lived internal connections (linear mgr memory growth to OOM) to DaemonServer::ms_handle_reset() never releases daemon_connections refs for non-OSD peers — unbounded AsyncConnection leak
- Affected Versions v20.2.0 added
- Affected Versions deleted (
v19.0.0)
ceph-mgr leaks one AsyncConnection (~1–2 KiB object + ~128 KiB recv_buf at default ms_tcp_prefetch_max_size) every time a non-OSD daemon connection is reset ungracefully. Observed as slow linear RSS growth (~1 MiB/h on an idle 3-mon Rook cluster) that never plateaus.
Root cause
DaemonServer::handle_open() stores a strong ConnectionRef for every non-client daemon:
// DaemonServer.cc (handle_open)
if (con->get_peer_type() != entity_name_t::TYPE_CLIENT &&
m->service_name.empty()) {
daemon_connections.insert(con);
}
But the only erase site is guarded to OSD peers:
// DaemonServer.cc (ms_handle_reset)
if (con->get_peer_type() == CEPH_ENTITY_TYPE_OSD) {
...
osd_cons[session->osd_id].erase(con);
auto iter = daemon_connections.find(con);
if (iter != daemon_connections.end())
daemon_connections.erase(iter);
}
MON and MDS daemons hit the insert path (every mon embeds a MgrClient whose _send_open() sends MMgrOpen with empty service_name), but their resets never erase. handle_close() does not touch daemon_connections either. Since the DaemonServer messenger uses Policy::stateless_server (lossy), every drop — including the default 900 s ms_connection_idle_timeout — goes through the reset path, and each reconnect inserts a fresh ref while the stale one is retained forever.
Evidence
- pprof --base diff over 8.5 h: 5.4 MB live, 97% cumulative under AsyncConnection::AsyncConnection / AsyncMessenger::add_accept.
- bpftrace lifecycle trace (40 min): _stop() and cleanup() fire 1:1; a residue of stopped connections never reaches the destructor despite cleanup() completing — i.e. a strong ref survives outside all messenger tracking sets. DispatchQueue::QueueItem releases its own ConnectionRef after reset delivery, leaving the stale daemon_connections entry as the sole owner.
- Messenger sets (conns/anon_conns/accepting_conns/deleted_conns) were dumped and shown bounded — they are not the holder.
Reproduction
Any cluster where mons/MDS connect to the active mgr and connections reset without MMgrClose (idle timeout, network drop, daemon crash). Watch AsyncConnection live bytes via tcmalloc heap profiles diffed with pprof.
NM Updated by Nitzan Mordechai 4 months ago
- Assignee set to Steven Zuraski
NM Updated by Nitzan Mordechai 4 months ago
- Priority changed from Normal to High
SZ Updated by Steven Zuraski 4 months ago
- Pull request ID set to 70839
SZ Updated by Steven Zuraski 4 months ago
- Pull request ID changed from 70839 to 70367
SZ Updated by Steven Zuraski 4 months ago
- Backport set to umbrella, tentacle, squid
YH Updated by Yaarit Hatuka 4 months ago
- Status changed from New to Fix Under Review
UB Updated by Upkeep Bot 4 months ago
- Status changed from Fix Under Review to Pending Backport
- Merge Commit set to 5c9ec2f0962fd905dbab3c198473fdb410d0deb7
- Fixed In set to v21.3.0-1951-g5c9ec2f096
- Upkeep Timestamp set to 2026-08-12T12:47:44+00:00
UB Updated by Upkeep Bot 4 months ago
- Copied to Backport #79418: umbrella: DaemonServer::ms_handle_reset() never releases daemon_connections refs for non-OSD peers — unbounded AsyncConnection leak added
UB Updated by Upkeep Bot 4 months ago
- Copied to Backport #79419: tentacle: DaemonServer::ms_handle_reset() never releases daemon_connections refs for non-OSD peers — unbounded AsyncConnection leak added
UB Updated by Upkeep Bot 4 months ago
- Copied to Backport #79420: squid: DaemonServer::ms_handle_reset() never releases daemon_connections refs for non-OSD peers — unbounded AsyncConnection leak added
UB Updated by Upkeep Bot 4 months ago
- Tags (freeform) set to backport_processed
UB Updated by Upkeep Bot 3 months ago
- Status changed from Pending Backport to Backporting
- Tags (freeform) deleted (
backport_processed) - Upkeep Timestamp changed from 2026-08-12T12:47:44+00:00 to 2026-08-27T18:45:11+00:00
UB Updated by Upkeep Bot 2 months ago
- Status changed from Backporting to Resolved
- Upkeep Timestamp changed from 2026-08-27T18:45:11+00:00 to 2026-09-29T13:06:30+00:00