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

Reset go away state #49

Merged
merged 2 commits into from
Dec 18, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ extension PickFirstLoadBalancer.State.Active {
if self.connectivityState == .idle {
// Current subchannel is idle and we have a new endpoint, move straight to the new
// subchannel.
self.isCurrentGoingAway = false
self.current = newSubchannel
self.parked[current.id] = current
onUpdateEndpoint = .connect(newSubchannel, close: current)
Expand All @@ -345,10 +346,12 @@ extension PickFirstLoadBalancer.State.Active {
onUpdateEndpoint = .connect(newSubchannel, close: next)

case (.none, .none):
self.isCurrentGoingAway = false
self.current = newSubchannel
onUpdateEndpoint = .connect(newSubchannel, close: nil)

case (.none, .some(let next)):
self.isCurrentGoingAway = false
self.current = newSubchannel
self.next = nil
self.parked[next.id] = next
Expand All @@ -368,6 +371,10 @@ extension PickFirstLoadBalancer.State.Active {
if connectivityState == self.connectivityState {
onUpdate = .none
} else {
// If the subchannel was going away and became idle then it went away.
if connectivityState == .idle {
self.isCurrentGoingAway = false
}
self.connectivityState = connectivityState
onUpdate = .publishStateChange(connectivityState)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ final class PickFirstLoadBalancerTests: XCTestCase {
case .connectivityStateChanged(.ready):
switch idleCount.value {
case 1:
XCTAssertNotNil(context.loadBalancer.pickSubchannel())
// Must be connected to server 1, send a GOAWAY frame.
let channel = context.servers[0].server.clients.first!
let goAway = HTTP2Frame(
Expand All @@ -307,6 +308,7 @@ final class PickFirstLoadBalancerTests: XCTestCase {
// Must only be connected to server 2 now.
XCTAssertEqual(context.servers[0].server.clients.count, 0)
XCTAssertEqual(context.servers[1].server.clients.count, 1)
XCTAssertNotNil(context.loadBalancer.pickSubchannel())
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Without the fix this returns nil even though a connection is ready and available to use.

context.loadBalancer.close()

default:
Expand Down
Loading