Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Sources/DistributedActors/Cluster/ClusterSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public struct ClusterSettings {
return UniqueNode(node: self.node, nid: self.nid)
}

/// Time after which a connection attempt will fail if no connection could be established
public var connectTimeout: TimeAmount = .milliseconds(500)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


/// Backoff to be applied when attempting a new connection and handshake with a remote system.
public var handshakeBackoffStrategy: BackoffStrategy = Backoff.exponential(initialInterval: .milliseconds(100))

Expand Down
6 changes: 3 additions & 3 deletions Sources/DistributedActors/Cluster/ClusterShell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,9 @@ extension ClusterShell {
serializationPool: self.serializationPool
)

return context.awaitResult(of: outboundChanElf, timeout: .milliseconds(500)) { result in
// the timeout is being handled by the `connectTimeout` socket option
// in NIO, so it is safe to use an infinite timeout here
return context.awaitResult(of: outboundChanElf, timeout: .effectivelyInfinite) { result in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

switch result {
case .success(let chan):
return self.ready(state: state.onHandshakeChannelConnected(initiated: initiated, channel: chan))
Expand Down Expand Up @@ -482,8 +484,6 @@ extension ClusterShell {
}
}

state._handshakes[remoteNode] = .initiated(initiated)

case .wasOfferedHandshake(let state):
preconditionFailure("Outbound connection error should never happen on receiving end. State was: [\(state)], error was: \(error)")
case .completed(let state):
Expand Down
1 change: 0 additions & 1 deletion Sources/DistributedActors/Cluster/ClusterShellState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ extension ClusterShellState {

switch state {
case .initiated(let initiated):
assert(initiated.channel != nil, "Channel should always be present after the initial initialization, state was: \(state)")
_ = initiated.channel?.close()
case .wasOfferedHandshake:
fatalError("abortOutgoingHandshake was called in a context where the handshake was not an outgoing one! Was: \(state)")
Expand Down
1 change: 1 addition & 0 deletions Sources/DistributedActors/Cluster/TransportPipelines.swift
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ extension ClusterShell {

let bootstrap = ClientBootstrap(group: group)
.channelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
.channelOption(ChannelOptions.connectTimeout, value: settings.connectTimeout.toNIO)
.channelInitializer { channel in
var channelHandlers: [(String?, ChannelHandler)] = []

Expand Down