fix(remote): clean up connections and goroutines on Factory.Create error paths #2069
All Vouch review confidence checks passed
Residual risk 0.15 = Change Risk (0.37) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.37 · 229 lines diff across 2 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.325
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #2069"
general
weight: 0.35
guolxingxing
Which issue(s) this PR fixes:
Issue longhorn/longhorn#14231
What this PR does / why we need it:
Factory.Create()inpkg/backend/remoteleaks resources on two error paths:1. If a later
connect()call fails, the TCP connections already established by earlier iterations are never closed.2. If
open()fails (e.g., the remote replica cannot be opened), thedataconn.Clientcreated from the connections is never closed. Eachdataconn.ClientholdsNumberOfConnectionsTCP connections and 5 goroutines (1 loop + 2 wire senders + 2 wire receivers), so every failedCreate()leaks 2 fds and 5 goroutines.In an HA storage system, engine startup with degraded/unreachable replicas performs repeated failed
Create()calls (e.g., via retries or replica rebuilding), which accumulates leaked fds and goroutines in the engine process and can eventually exhaust resources.This PR closes the already-established connections on
connect()failure, and callsdataConnClient.Close()onopen()failure to tear down the connections and goroutines.Special notes for your reviewer:
The regression test
TestFactoryCreateNoLeakOnOpenFailureuses a fake gRPC replica server that failsReplicaOpen, then quantifies fd and goroutine leaks by comparing counts before and after 10 failedCreate()calls. The assertions use a tolerance threshold to avoid flakiness from unrelated background activity.Additional documentation or context
Leak reproduction evidence is available in longhorn/longhorn#14231: before the fix, 10 failed
Create()calls leaked 20 fds and 50 goroutines; after the fix, 0 fds and 0 goroutines.``
release-note
Fixed a resource leak in remote backend Factory.Create error paths that leaked TCP connections and goroutines on failed replica creation