Fix tend-thread busy-loop on NodeValidator silent failure#16
Merged
Conversation
5179ed3 to
8fb3ac9
Compare
A bare rescue in NodeValidator#get_hosts lets a half-initialized validator escape to Cluster#create_node, producing a Node with @host = nil that crashes every subsequent tend cycle. The tend loop's sleep on the success path of begin/rescue turned that into a CPU-pegged busy-loop at ~50 errors/sec until pid restart. - NodeValidator: post-condition raises InvalidNode if @name nil or @Aliases empty; log swallowed errors at debug instead of bare rescue. - Node::Refresh::Peers: integration-point guard skips half-initialized validators before cluster.create_node (covers the @name-set, aliases-empty path the existing mismatch check cannot catch). - Cluster#launch_tend_thread: explicit begin/rescue with outer sleep prevents busy-loop on persistent tend failures. Specs cover all four NodeValidator silent-failure paths, both half- init shapes in Peers refresh, and rescue-path-sleep behavior; each fix verified by revert-and-rerun. INF-684
8fb3ac9 to
0d667dc
Compare
mknapik
approved these changes
Apr 27, 2026
afterdesign
approved these changes
Apr 27, 2026
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.
Fixes INF-684.
TL;DR
Production incident on 2026-04-24: a single Ruby pid's Aerospike tend thread busy-looped at ~50 errors/sec for ~1 hour during a peer-node flap, returning 5XX from
/v1/riskuntil the pid was rolled. Three layered fixes restore self-healing.Root cause
A bare
rescueinNodeValidator#get_hostssilently swallows connection / info-request errors. When a server hangs, the constructor returns a half-initializednv(@name = nil,@aliases = []) that escapes intoCluster#create_node→ produces aNodewith@host = nil→ next tend cycle callshost.nameon nil →NoMethodError.The tend loop's
sleepsat on the success path of an implicitbegin/rescue, so the rescue path skipped backoff and pegged CPU at ~50 iterations/sec.Production log signals
Two lines from pid 361 (tend thread
26450112) captured the bug:␣is annotation; the raw log has a literal space —"actual node #{nv.name}"withnv.name = nilrenders as a double-space gap, invisible in any rendered view. That's why the warning slipped past triage: it looked like a benign spacing artifact, not a state-corruption signal.Four silent-failure paths in NodeValidator
@nameis set only insideget_hosts, after a successful info round-trip. Four points can leave it nil — all silent:Cluster::CreateConnectionraisesname=nil, aliases=[]Info.requestraises (incident's path)name=nil, aliases=[]info_map['node']is nilname=nil, aliases=[]info_map[address_command].splitraisesname=set, aliases=[]Path 4 is special.
@nameis assigned before theNoMethodError, so the existingnv.name != peer.node_namemismatch check atpeers.rb:46does not fire and the half-initnvfalls through tocluster.create_node. This is why Fix B's guard tests both predicates and must run before the mismatch check.Fixes
A —
lib/aerospike/node_validator.rbPost-condition raising
Aerospike::Exceptions::InvalidNodewhen half-initialized; barerescuebecomesrescue => ewith debug-level logging. Closes all four paths at the source.InvalidNodeis already anAerospike::Exceptions::Aerospikesubclass, so the existing rescue atpeers.rb:60catches it for free.B —
lib/aerospike/node/refresh/peers.rbDefense-in-depth guard before the mismatch check:
next(notbreak) — other hosts of the same peer might validate fine.C —
lib/aerospike/cluster.rbRestructure
launch_tend_threadfrom implicitbegin/rescue(withsleepon the success path) to explicitbegin/rescuewithsleepoutside, so backoff runs unconditionally. Without this, any future tend pathology — not just this bug — pegs CPU.Self-healing
With these fixes, a hung peer no longer corrupts
@cluster_nodes. Each tend cycle re-attempts validation; the client recovers automatically once the server-side cluster prunes the bad peer. No process restart needed.Tests
8 new examples; each verified to fail when its corresponding fix is reverted:
node_validator_spec.rbexpected InvalidNode but nothing raisedpeers_spec.rb(new)nextvsbreak)peers.nodescontained{"BB92118BAB14E12" => nil}cluster_spec.rbCI's global
Support.clienttend thread caused intermittent mock conflicts in 4 pre-existingnode_validator_spectests; switched those toallow(...)(fromexpect(...).to receive) to tolerate background callers without losing assertions.Notes
aerospike/aerospike-client-rubymaster too — an upstream version bump would not fix it.