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

Delay closing until the next loop tick #1326

Merged
merged 1 commit into from
Dec 14, 2021
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
8 changes: 6 additions & 2 deletions Sources/GRPC/GRPCIdleHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,12 @@ internal final class GRPCIdleHandler: ChannelInboundHandler {
}

// Close the channel, if necessary.
if operations.shouldCloseChannel {
self.context?.close(mode: .all, promise: nil)
if operations.shouldCloseChannel, let context = self.context {
// Close on the next event-loop tick so we don't drop any events which are
// currently being processed.
context.eventLoop.execute {
context.close(mode: .all, promise: nil)
}
}
}

Expand Down
1 change: 1 addition & 0 deletions Tests/GRPCTests/ConnectionManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@ extension ConnectionManagerTests {
payload: .goAway(lastStreamID: 1, errorCode: .noError, opaqueData: nil)
)
XCTAssertNoThrow(try channel.writeInbound(goAway))
self.loop.run()
}

self.loop.run()
Expand Down