Skip to content

Commit

Permalink
Add an assertion failure if the channel's closeFuture is failed
Browse files Browse the repository at this point in the history
  • Loading branch information
gjcairo committed Dec 17, 2024
1 parent 908ff24 commit 01c568c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Sources/NIOCore/AsyncChannel/AsyncChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,20 @@ public struct NIOAsyncChannel<Inbound: Sendable, Outbound: Sendable>: Sendable {
// We ignore errors from close, since all we care about is that the channel has been closed
// at this point.
self.channel.close(promise: nil)
// `closeFuture` is never failed, so we can ignore the error
try? await self.channel.closeFuture.get()
// `closeFuture` should never be failed, so we could ignore the error. However, do an
// assertionFailure to guide bad Channel implementations that are incorrectly failing this
// future to stop failing it.
do {
try await self.channel.closeFuture.get()
} catch {
assertionFailure(
"""
The channel's closeFuture should never be failed, but it was failed with error: \(error).
This is an error in the channel's implementation.
Refer to `Channel/closeFuture`'s documentation for more information.
"""
)
}

return result
}
Expand Down

0 comments on commit 01c568c

Please sign in to comment.