Skip to content
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

Fix connection timeout when retries are set to none #1650

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
15 changes: 11 additions & 4 deletions Sources/GRPC/ConnectionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -942,18 +942,24 @@ extension ConnectionManager {
// states. Must be called on the `EventLoop`.
private func startConnecting() {
self.eventLoop.assertInEventLoop()
var timeout: TimeAmount?
if let backoff = self.connectionBackoff {
timeout = TimeAmount.seconds(timeInterval: backoff.minimumConnectionTimeout)
}
switch self.state {
case .idle:
let iterator = self.connectionBackoff?.makeIterator()
self.startConnecting(
backoffIterator: iterator,
muxPromise: self.eventLoop.makePromise()
muxPromise: self.eventLoop.makePromise(),
connectTimeout: timeout
)

case let .transientFailure(pending):
self.startConnecting(
backoffIterator: pending.backoffIterator,
muxPromise: pending.readyChannelMuxPromise
muxPromise: pending.readyChannelMuxPromise,
connectTimeout: timeout
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't need to do this for the transientFailure case: transientFailure means we tried to connect and fail, in which case we'll already have the backoffIterator and we should use the values from that instead.

)

// We shutdown before a scheduled connection attempt had started.
Expand All @@ -973,7 +979,8 @@ extension ConnectionManager {

private func startConnecting(
backoffIterator: ConnectionBackoffIterator?,
muxPromise: EventLoopPromise<HTTP2StreamMultiplexer>
muxPromise: EventLoopPromise<HTTP2StreamMultiplexer>,
connectTimeout: TimeAmount? = nil
) {
let timeoutAndBackoff = backoffIterator?.next()

Expand All @@ -985,7 +992,7 @@ extension ConnectionManager {
let channel: EventLoopFuture<Channel> = self.channelProvider.makeChannel(
managedBy: self,
onEventLoop: self.eventLoop,
connectTimeout: timeoutAndBackoff.map { .seconds(timeInterval: $0.timeout) },
connectTimeout: connectTimeout,
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we don't have a connectTimeout we should fallback to using timeoutAndBackoff.map { .seconds(timeInterval: $0.timeout) }

logger: self.logger
)

Expand Down