Stop the resource manager on shutdown #799
All Vouch review confidence checks passed
Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 605 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.383
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #799"
general
weight: 0.35
klihub
The problem
resmgr.Stop()has never been called in production.Main.Run()ends withand
Start()blocks in the config agent's event loop, so nothing follows it. OnSIGTERM we stop the agent, the loop returns,
Run()returns — and the processdisappears from under its own subsystems. Nobody calls
resmgr.Stop(), so theNRI stub is never stopped and the runtime is left to notice a closed socket on
its own.
git log -S "mgr.Stop()"confirms the call was never there.The fix
This PR calls it, on the way out of
Run():Two things had to be fixed for that call to be safe:
nriPlugin.stop()dereferencedp.stub, which onlystart()ever assigns.Stop()is now reachable on paths wherestart()never ran, so it returnsearly on a nil stub.
Agent.Stop()waited ondoneC, a channel which is declared but nevercreated or closed, so it never returned. Nothing noticed, since its only
caller is a goroutine and the event loop was already on its way out. The wait
is gone; closing
stopCis what makesStart()return.stopCis no longercleared either, so the two goroutines selecting on it don't race with
Stop().Also trimmed a comment in the signal handler which claimed we clean up
published extended resources on the way out. We don't, and per the earlier
discussion we shouldn't — that state belongs to reconciliation, not to an exit
handler.
What the shutdown path does — and should keep doing
This makes
Stop()reachable, which makes it an inviting place to hangresource cleanup off. It deliberately does none, and shouldn't grow any. In
full, a signalled plugin now does:
Agent.Stop(): one status PATCH clearing this node's entry in the configresource's
.status.nodes(pre-existing, 10s timeout), thenclose(stopC),which makes the config watches and the extended-resource reconciliation loop
return.
resmgr.Stop():nri.stop(), i.e.stub.Stop(), closing the NRIconnection.
Nothing else. No policy teardown — there is no
policy.Stop()to call — andnothing that walks containers. Frequencies, governors, SST configuration, IRQ
and CPU affinities are left as they are; published extended resources stay
published; NRT custom resources are not deleted. The work is O(1) and does not
scale with container count, so there is no realistic way for the kubelet's
SIGKILL to catch us half-way through, and no partly-done state that could be
more disruptive than no cleanup at all. Reconcile-to-effective-configuration on
start remains the only mechanism that converges system state, and the cache the
next instance reconciles from is untouched — which is exactly the conclusion of
the earlier review discussion about clean-up on exit.
Out of scope
No node-state cleanup on exit (extended resources, policy hooks) — see above
for why. No context plumbing either. A lifetime
contextwould be a reasonablecleanup on its own — today's contexts are all leaves,
context.Background()handed to
stub.Startand to the config watches — but here it would add amechanism without replacing one: cancelling a context does not stop the NRI
stub, the controllers or the HTTP server, which have
Stop()methods instead.Testing
New e2e test,
policies.test-suite/topology-aware/n4c16/test41-graceful-shutdown. It signalsthe plugin with SIGTERM and asserts, from the log of the terminated instance,
that handling the signal took it through stopping the resource manager and
closing the NRI connection, and that the process exited with 0. It signals the
process rather than deleting the pod, because that restarts the container in
place and keeps the previous instance's log readable; reading it needs the new
--previousoption inplugin-log.The test was verified to detect the regression it guards, against a live
cluster: it passes with these commits, fails with
error: the resource managerwhen the fix is reverted and the image rebuilt,was not stopped on shutdown
and passes again once it is restored. The exit-code assertion alone would not
have caught it — unfixed, the plugin still exits 0, it just skips stopping its
subsystems.
test00-basic-placement,test09-container-exitandtest12-config-statusalso pass, the last one covering both a plugin terminated mid-run and one which
fails on its initial configuration. Unit tests,
go vetandgofmtare clean.Log on SIGTERM, where previously it stopped after the agent: