fix: prune dead stratum workers instead of unbounded growth - #3901
Conversation
Worker stats slots were append-only, so reconnect churn left a long list of disconnected workers in the TUI/API. Reuse disconnected slots for new connections, clear stats when the last worker leaves, auto-compact after more than 32 dead slots, and expose prune_dead_workers for explicit cleanup. Closes mimblewimble#2413
wiesche89
left a comment
There was a problem hiding this comment.
This addresses the growth problem behind #2413 automatically, rather than adding the requested manual prune action, and the separate stats reset request remains out of scope. Could the PR description clarify that distinction and use Refs #2413 unless the automatic replacement is considered sufficient to close the issue?
|
|
||
| /// Remove disconnected worker stats and reassign live worker IDs densely. | ||
| /// | ||
| /// Safe to call while workers are connected: live workers are remapped |
There was a problem hiding this comment.
I don't think remapping live workers is safe here. Each connection task captures its worker_id at accept time and keeps using it for RPCs, replies, stats, and disconnect. After a remap that ID can point to another worker or outside the stats vector. Could we keep connection IDs stable and add a test that continues using the original ID after cleanup?
| // does not grow without bound under reconnect churn (#2413). | ||
| let worker_id = stratum_stats | ||
| .worker_stats | ||
| .iter() |
There was a problem hiding this comment.
remove_worker() marks the stats disconnected before removing the worker from the map. A concurrent accept can reuse and replace that slot in between, after which the old disconnect removes the new connection. Could we make removal and the disconnected-state update atomic under the same locks?
Summary
Stratum
worker_statswas append-only: every reconnect left a permanent disconnected entry. With rigs cycling connections the TUI mining table (and mining status API) grew without bound until node restart.Closes #2413
Changes
prune_dead_workers(): explicit compact/remap helper (returns removed count)Live worker IDs only change during prune/remap (under write locks). Day-to-day operation uses slot reuse without remapping.
Test plan
cargo test -p grin_servers --lib stratumserver::tests