-
Notifications
You must be signed in to change notification settings - Fork 6
libstore: Improve SSH connection sharing #311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughisMasterRunning and addCommonSSHOpts now accept an explicit Path socketPath and all call sites were updated to pass it. startMaster returns the literal string "none" when SSH master mode is disabled instead of an empty string; the SSH Changes
Sequence Diagram(s)Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
What is this CodeRabbit "Docstring Coverage" warning supposed to tell me? |
|
I'm also not satisfied by the CodeRabbit's summary and review time estimation. I want to draw special attention to the modified condition here: The summary didn't explicitly note this change, which in my opinion would need the most scrutiny. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/libstore/ssh.cc (2)
119-128: Add a comment explaining the precondition.The
assert(useMaster)enforces an important precondition, but lacks explanation. Consider adding a comment to clarify whyisMasterRunningshould only be called when Nix is managing the SSH master.📝 Suggested comment
bool SSHMaster::isMasterRunning(Path socketPath) { + // This function should only be called when useMaster is true, + // as checking master status is only meaningful when Nix manages the SSH master. assert(useMaster);
235-235: Consider defining a constant for the "none" socket path.Returning the literal string
"none"is correct (SSH's-S nonedisables connection sharing), but using a magic string reduces clarity. Consider defining a named constant.🔧 Suggested refactor
At the top of the file or in the class definition:
static constexpr const char * NO_SSH_MASTER_SOCKET = "none";Then use it here:
if (!useMaster) - return "none"; + return NO_SSH_MASTER_SOCKET;
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/libstore/include/nix/store/ssh.hhsrc/libstore/ssh.cc
🚧 Files skipped from review as they are similar to previous changes (1)
- src/libstore/include/nix/store/ssh.hh
🧰 Additional context used
🧬 Code graph analysis (1)
src/libstore/ssh.cc (1)
src/libstore/include/nix/store/ssh.hh (2)
args(42-42)socketPath(43-43)
🔇 Additional comments (6)
src/libstore/ssh.cc (6)
92-117: LGTM: Socket path is now explicitly controlled.The addition of the
socketPathparameter and the-Soption ensures that SSH uses the correct control socket (or "none" to disable sharing). This prevents Nix from inadvertently probing or interfering with user-managed SSH control sockets.
156-156: LGTM: Consistent socket path handling.Calling
startMaster()unconditionally is correct—it returns"none"when not using master mode, which is then properly handled throughout the function.
189-189: LGTM: Socket path correctly propagated.The
socketPathobtained fromstartMaster()is correctly passed toaddCommonSSHOpts, ensuring the-Soption uses the appropriate control socket or "none".
252-252: LGTM: Assert precondition is satisfied here.At this point in
startMaster(), the early return on line 235 ensuresuseMasteris true, so theassert(useMaster)on line 121 will pass. The call is safe.
267-267: LGTM: Correct socket path used for master startup.Passing
state->socketPathtoaddCommonSSHOptsensures the SSH master process is started with the correct control socket path via the-Soption.
210-210: Verify the corrected logic prevents probing user-managed sockets.This is the critical fix mentioned in the PR description. The new condition
!(useMaster && isMasterRunning(socketPath))ensures that:
isMasterRunningis only called whenuseMasteris true (via short-circuit evaluation), respecting the assert on line 121- Nix no longer probes SSH sockets when
useMasteris false, preventing interference with user-managed SSH ControlMaster configurationsBoth call sites to
isMasterRunningare properly protected: at line 210 via short-circuit AND evaluation, and at line 252 via the early return guard instartMaster()(if (!useMaster) return "none";at line 239). The logic is correct, though the double negation could be replaced with the equivalent form!useMaster || !isMasterRunning(socketPath)if clarity is preferred.
Motivation
I've been experiencing errors when attempting remote store builds:
This only happens with
DeterminateSystemd/nix-src, not with upstream Nix.The underlying issue is my default
ControlMaster/ControlPathconfiguration for SSH connection sharing.I've looked into the
SSHMasterconnection code in Nix and identified some oddities.SSHMaster::isMasterRunningdoesn't specify the control socket that needs to be checked and thus falls back to the one that I've configured, the lifetime of which is not managed by Nix. Nix shouldn't try to interact with those sockets because checking for such a master's existence and then acting on it is inherently racy.Context
I fixed the
SSHMaster::isMasterRunningfunction by adding asocketPathparameter. This function should only be called whenuseMasteristrue, which I've now checked byassert.This then caught another bug: The condition
!useMaster && !isMasterRunning()inSSHMaster::startCommandis nonsensical; it will only checkisMasterRunningifuseMasterisfalse.I also ensured that Nix explicitly disables connection sharing when
SSHMaster::useMasterisfalseby adding-S none.Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.