You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[release-0.x] fix: make Disconnect safe to call concurrently - #508
Connection now holds its client in an atomic.Value (a mutex would make the by-value embedded Connection uncopyable), and each method loads the client once, so Disconnect from another goroutine no longer races IsConnected/Exec.
Connection.client was read and written without synchronization, so
calling Disconnect from another goroutine raced IsConnected and the
Exec methods, and could hand them a nil client.
The client is now held in an atomic.Value, which unlike a mutex keeps
Connection copyable for the types embedding it by value, and each method
loads it once.
Fixes#498
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
The reason will be displayed to describe this comment to others. Learn more.
π‘ Changes recommended
The atomic client swap leaves WinRM and OpenSSH transport state vulnerable to races with Disconnect, including a potential nil dereference during execution.
WinRM cleared its client and OpenSSH its connected flag without synchronization while commands read them, so those are now atomic and WinRM commands use the client they loaded. Connection keeps its client behind a shared, mutex guarded pointer instead of an atomic.Value, which must not be copied after first use either, and the concurrency test now disconnects deterministically between the connection check and the command.
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
The reason will be displayed to describe this comment to others. Learn more.
π‘ Changes recommended
The regression test orders client reads around Disconnect and would pass even without the holderβs locks, leaving concurrent-access synchronization untested.
Qualify Disconnect interruption behavior by transport
connection.go:422
The claim that Disconnect makes running commands fail does not hold for every transport: WinRM only clears its client pointer, and Localhost's disconnect is a no-op. In-flight commands can therefore continue running or blocking after Disconnect returns. Qualify interruption as transport-dependent rather than promising cancellation for all connections.
The ordered test only covers the nil-client interleaving. Also qualify Disconnect's doc: whether a running command is interrupted depends on the transport.
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
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
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.
Connectionnow holds its client in anatomic.Value(a mutex would make the by-value embeddedConnectionuncopyable), and each method loads the client once, soDisconnectfrom another goroutine no longer racesIsConnected/Exec.Fixes #498
π€ Generated with Claude Code