Bounty
XE-0040 · Bounty

net/sync: no in-flight guard on sync rounds; ordinary first sync reaches 1.9 GB RSS and 2.7 cores, OOM on a 2 GB node (High)

Awarded High xe#59 filed 2026-10-26 07:33 UTC by senastor

Report

Track 2 measurement: resource exhaustion during ordinary catch-up. No malformed input and no campaign load were used.

Summary

SetupSync starts a requestSync goroutine on every new peer connection and again on every 10 second tick for each peer whose frontier is behind. The only backpressure is syncRateLimiter, a 5 second per-peer cooldown that limits starts, not concurrency. Each request may live for 60 seconds and buffers up to 10,000 decoded blocks before applying them. A round that cannot apply its blocks lasts tens of seconds, so later ticks start more rounds for the same peer while the previous ones are still running. On testnet-0005 at commit 978785929bc1 a fresh node with six peers reached 75 concurrent requestSync goroutines, 1.86 GB RSS, 2.7 cores and 41.9 million goroutine IDs in under three minutes, while its data directory was only 252 MB. On a 2 GB VPS this is an OOM during first sync once additional peer IDs multiply the rounds, and the controlled run below reproduced it under a 2 GiB cgroup; on a larger host the node saturates cores and still does not converge, so the state repeats every tick.

Affected component

  • net/sync.go:22-37: defaultPageSize = 64, maxPageSize = 256, maxTotalBlocks = 10000, maxServerBlocks = 10000, periodicSyncInterval = 10s, syncCooldown = 5s, maxSyncResponseBytes = 10 MiB.
  • net/sync.go:328-351 (ConnectedF): spawns requestSync for every connection, gated only by outboundRL.
  • net/sync.go:363-387 (ticker): every 10 seconds spawns requestSync for each peer where tracker.shouldSync is true.
  • net/sync.go:49-68: syncRateLimiter.allow returns false only within 5 seconds of the previous start for the same peer. It keeps no in-flight state.
  • net/sync.go:536-596: the request accumulates allBlocks until 10,000 blocks, then applies them with up to 10 retry passes. allBlocks stays referenced until the function returns.
  • net/sync.go:531: the 60 second context derives from context.Background().

Measurement

Two fresh runs, same host, same binary (master 978785929bc1, xe 9787859). The data directory was removed before each run. The node used the two documented bootstrap dials with --no-discovery --disable-mdns. Samples were taken every 5 seconds from /proc/<pid>/status, /metrics and /node.

metric idle (no peers) run 1 run 2
duration 15 s 151 s 120 s
peers 0 6 6
accounts 1 4,617 4,379
blocks 1 20,817 17,787
RSS 34 MB 1.82 GB at the last sample, 1.86 GB metric peak 1.33 GB at the last sample, VmHWM 1.46 GB
CPU 1.9 % of one core 2.72 cores 2.73 cores
live goroutines 98 521 486
max goroutine ID n/a 41,938,183 32,581,639
goroutine IDs per second n/a ~238,000 ~263,000
concurrent requestSync at SIGQUIT n/a 75 62
hit maxTotalBlocks cap log lines 0 62 52
data directory n/a 252 MB 157 MB
API latency, median / max ~2 ms ~30 ms / 116 ms ~31 ms / 132 ms

CPU is the delta of utime + stime at 100 Hz over the sampling window. Goroutine IDs per second are derived from the maximum ID in the SIGQUIT dump and the process age at that dump. The concurrent counts are from the dumps, 728 and 758 goroutines in total.

The heap is 6 to 9 times the on-disk data. The periodic path alone allows 60 s / 5 s = 12 starts per peer, so 72 rounds for six peers, and the connection callback adds one more per connection; this matches the observed 75 and 62. At 10,000 buffered blocks per round this is up to 720,000 block slots, or 1.4 to 1.9 GB at 2 to 2.6 KB per signed block, which is consistent with the measured peak. That last step is arithmetic from the caps, not a heap profile; the repository exposes no pprof endpoint.

Sybil amplification (measured)

The per-peer bound suggests that peer identities multiply the work. Three controlled runs used the same host, the same binary and a copied chain of 4,379 accounts and 17,787 blocks served by local nodes. Each source had a freshly generated host.key, so the victim saw eight distinct libp2p peer IDs; all sources shared the copied ledger identity, which the sync limiter does not key on. The victim ran in a cgroup v2 with memory.max = 2 GiB and no swap. The sources ran on loopback on the same 4 core host, so CPU was oversubscribed; the victim's own resource counters remain valid, but wall clock gaps reflect host contention.

case peers seen concurrent requestSync at dump peak RSS / VmHWM CPU outcome
1 source 1 3 212 MB 0.36 cores survived 87 s
8 sources 8 110 1.23 GB 1.31 cores survived 147 s
8 sources plus public network 15 (8 local + 7 public) no dump 1.40 GB last readable VmHWM 1.31 cores to the last sample cgroup OOM killed at 157 s, oom_kill=1

With the same chain, eight peer IDs produced 37 times the concurrent rounds and 5.8 times the memory of one. The eight-source case stayed below 2 GiB because the copied chain is static and stops offering new blocks. Adding the live public chain and its peers crossed the limit: the victim was killed by the cgroup OOM killer, the last readable sample had 3,211 accounts and 11,206 blocks, and the log shows repeated hit maxTotalBlocks cap (10000) immediately before the kill.

Reproduction

  1. Build master 978785929bc1.
  2. Start a node with a fresh data directory:
./xe node --genesis-dir ./genesis/testnet-0005 --data ./data \
  --api-port 28100 --metrics-addr 127.0.0.1:29120 --port 29020 \
  --no-discovery --disable-mdns \
  --dial <bootstrap-ams>,<bootstrap-nyc>
  1. Every 5 seconds record VmRSS and VmHWM from /proc/<pid>/status, go_goroutines and process_resident_memory_bytes from /metrics, and accounts and block_count from /node.
  2. After 120 to 150 seconds send SIGQUIT and count requestSync frames in the dump.

Observed in both runs: 62 and 75 concurrent requestSync, 1.46 and 1.86 GB peak, 2.7 cores, and rounds that end with 5,343 to 5,980 blocks could not be added after retries.

Why the rounds overlap

A round ends only after it has applied its page or exhausted the retries. In these runs the client hit the 10,000 block cap dozens of times, and 5,343 to 5,980 blocks per round failed with signature: unopened account ... has no declared signature. isRetryableError keeps those blocks pending, so the round spends all 10 passes and often the full 60 second deadline. Meanwhile syncCooldown has already allowed two to twelve new starts for the same peer. shouldSync compares frontiers, and the frontier does not move for blocks that fail, so every tick qualifies again.

Impact

Onboarding: the documented bootstrap path alone reached 1.86 GB RSS and 2.7 of 4 cores on this host in 151 seconds, before the node reached the network's account count, and did not converge. Under a 2 GiB cgroup, the same public sync plus eight source peer IDs was OOM-killed at 157 seconds. The API stayed responsive in these runs, so the failure is resource saturation rather than API starvation; on a smaller host the process dies first.

The bound is per peer, not global. Six peers means 12 rounds per peer ID, and the first connection of a new peer ID always passes the cooldown. The controlled runs above show the multiplier: eight source peer IDs on one host raised the concurrent rounds from 3 to 110, and adding those eight to a victim that was also syncing the live public network took the process past the 2 GiB cgroup limit in 157 seconds. A peer that keeps advertising a frontier the node cannot apply, or several peer IDs doing so, can hold the node at this level.

Suggested severity

High. Ordinary first sync of the public testnet reaches 1.86 GB RSS and 2.7 of 4 cores with no malicious input, and adding eight peer IDs that serve an ordinary chain OOM-kills the process under a 2 GiB cgroup in 157 seconds. This is not the single decoded page described in #44: every round here stays within the 10,000 block cap, and that cap is what multiplies across overlapping rounds.

Suggested fix

  • Single-flight per peer: skip the periodic start while a request for that peer is active. The tracker already stores per-peer state.
  • Add a global semaphore or byte budget for concurrent rounds and buffered blocks, not only a per-peer start cooldown.
  • Apply pages as they are decoded instead of accumulating up to 10,000 blocks.
  • Bound the buffer by bytes with maxSyncResponseBytes, and drop blocks that are already known to be retryable and pending.
  • Derive the request context from the node context so shutdown cancels these rounds.

XE payout address: will be provided in a follow-up comment.

Thread

senastor2026-10-26 07:37 UTCgithub

XE payout address: 3af6fd8452352903a845a4b99a0f852a9f944bbab4afd6cfaab93cfb11510a9a