Repository navigation
fix(xtcp): tcp destination queue, deadlines, and re-dial (#345 freeze, #339 restart blind) - #352
Merged
Merged
Conversation
…345 poller freeze and the #339 restart-on-sink-outage blind The delivery-outage suite (PR #346) surfaced two ways a sink-side fault could stop xtcp2 from reporting TCP statistics about the base OS and non-attacker containers, while every /metrics scrape kept answering 200: - #345 (rt-11-5, CONFIRMED 16/16): with the sink IP ARP-blackholed, a blocked Write "succeeds" into SO_SNDBUF and the retransmit window (hours at prod knobs) — the poller froze behind it with zero counters. - #339 (rt-4-7): a down sink at startup aborted collection outright, and a sink that dies mid-run never re-dialed: tcpDest held a dead conn forever, so every record since the outage was lost silently. Product fixes, driven by the scenarios: - destinations_queue.go (new, untagged — the tcp destination compiles into every flavor incl. stdlib-only min): envelopeQueue moves out of s3queue.go and is shared; backoffWindow kept verbatim (its jitter tests pin the attempt-4 and attempt>=33 boundaries). - destinations_tcp.go rewritten around a bounded queue + one background worker: Send never blocks (evicts oldest, counts xtcp_tcp_dropped_total{reason}/_bytes_total and buffered-bytes), SetWriteDeadline(now+writeTimeout) on every dial and write — a blocked write now fails in bounded time and re-dials under full-jitter backoff (cap clamped from poll_frequency/10) up to tcpWriteMaxAttempts before drop-and-count. Lazy dial: a down sink at start no longer aborts the daemon (#339's other half); the worker dials when delivery begins. Dial moved outside connMu — under it, Close's dropConn could block on the mutex for the length of a dial. Close drains the queue for tcpWorkerDrainTimeout then drops the conn. - New knobs, all belt-bounded and proto-validated (fields 120-122): tcp_write_timeout (default 30s, [1s,1h]), tcp_queue_depth (16), tcp_max_buffered_bytes; flags -tcpWriteTimeout/-tcpQueueDepth/ -tcpMaxBufferedBytes, env TCP_WRITE_TIMEOUT/TCP_QUEUE_DEPTH/ TCP_MAX_BUFFERED_BYTES, deploy axis XTCP2_TCP_WRITE_TIMEOUT. - New destTCP counters: Dial, Reconnect, queueFull, dropped, Writes, WriteBytes — the blind is now VISIBLE and COUNTED while dark. Scenario flips, both re-run green on the fixed build: - rt-11-5: CONFIRMED -> MITIGATED (18/18, 20261126T111738-209ab068a- 1688938): polls keep issuing through the stall, Write/Dial errors and drops counted, de-poison heals with no restart; cycle 2 repeats. - rt-4-7: split verdict -> BLOCKED end to end (15/15, 20261126T110001- 209ab06-1548426): outage counted, polls continue, catcher restart heals delivery with no daemon restart (reconnects=1). Fixes #345. Fixes #339.
The matrix re-provisions the same VMs for hours, and the cloud image's apt-daily timers fired mid-run: rt-11-3, rt-2-9, rt-4-7, rt-11-4, and rt-11-5 (the last five scenarios, in a cascade) all failed provisioning with 'E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process (unattended-upgr)' — an environmental failure, not a product one; every scenario before it passed, 28/33 total. common.sh (the first provisioner on both guests) now stops and masks the apt-daily timers and unattended-upgrades, then waits out any in-flight run (bounded, 10 min) before the first apt call. The docker block below needs the lock too on a fresh VM, so the guard runs before it. attacker.sh already had this wait for re-provisions; common.sh is where the race actually hit.
The matrix regression (28/33, five environmental dpkg-lock failures fixed separately) surfaced a neighbor-state race in the rt-11-5 dark-window assert: the write deadline closes the conn, a re-dial falls back to broadcast ARP, the REAL sink answers, and delivery SELF-HEALS mid-poison — 1262 lines/6s while the attack continues (a REACHABLE entry then ignores the poison's gratuitous replies for ~30s, so the re-poison can't re-stall it inside the window). That run failed 16/18 with both misses being the scenario demanding shape A (sustained stall, drops counted) when the product had delivered shape B (healed-through, zero drops, loss bounded to the reconnect window) — a stronger mitigation, not a regression. The scenario now asserts the invariants that matter and accepts either shape: Write/Dial errors MUST rise (flowing with zero errors = the poison failed or the stall went silent), the poller MUST keep issuing, and de-poison MUST heal without a restart. Shape A still requires the drops be counted (with a late-heal escape — an envelope budget takes ~30s to burn); cycle 2 requires new Write errors (a flipped entry makes the in-flight write error within ~5s, so no new errors = a silent stall). Re-verified 18/18 MITIGATED, shape A (20261127T071651-195d45c15-986471): dark 0 lines/6s, drops=3, polls 52->77 through the stall, heals at reconnects=1, cycle 2 repeats.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #345. Fixes #339. Lands the product fixes the delivery-outage suite (PR #346) surfaced.
The findings
/metricsscrape keeps answering 200. The blind was total and silent.The fixes
pkg/xtcp/destinations_queue.go(new, untagged):envelopeQueuemoves out ofs3queue.goand is shared by both destinations — the tcp destination compiles into every flavor including stdlib-onlymin, so no build tag;backoffWindowkept verbatim (its jitter tests pin the attempt-4 and attempt-≥33 boundaries).pkg/xtcp/destinations_tcp.gorewritten around a bounded queue + one background worker:Sendnever blocks: evicts oldest, countsxtcp_tcp_dropped_total{reason}/_bytes_total+xtcp_tcp_buffered_bytes{stage="queue"}SetWriteDeadline(now+writeTimeout)on every dial and write — a blocked write now fails in bounded time instead of freezing the pollerconnMu— under it,Close'sdropConncould block on the mutex for the length of a dialClosedrains the queue fortcpWorkerDrainTimeout(5s) then force-drops the conntcp_write_timeout(default 30s, belt [1s, 1h]),tcp_queue_depth(16),tcp_max_buffered_bytes;-tcpWriteTimeout/-tcpQueueDepth/-tcpMaxBufferedBytes;TCP_WRITE_TIMEOUT/TCP_QUEUE_DEPTH/TCP_MAX_BUFFERED_BYTES; deploy axisXTCP2_TCP_WRITE_TIMEOUT(Vagrantfile arg 12).destTCPcounters: Dial, Reconnect, queueFull, dropped, Writes, WriteBytes — the blind is now VISIBLE and COUNTED while dark.TestBuildConfigfixture extended.Scenario flips (expectations travel with fixes and fail CI)
20261126T111738-209ab068a-1688938, TCP_WRITE_TIMEOUT=5s, two poison cycles): polls keep issuing through the stall (25→47 over 32s — the freeze is gone), Write/Dial errors and drops counted while dark, scrape 200; de-poison heals delivery with no daemon restart (reconnects=1, 2498 lines/6s); cycle 2 repeats (Write/error 10→14, heals again at 2500 lines/6s).20261126T110001-209ab068a-1548426): outage counted (Write/error=24, Dial/error=25, drops=9), polls continue, catcher restart heals delivery with no daemon restart (reconnects=1, 2482 lines/6s).Testing
go test ./pkg/xtcp/ ./cmd/xtcp2/wait_for, not a sleep