From 01c568cf71160b1c42b31d2eb364b398750e8885 Mon Sep 17 00:00:00 2001 From: Gus Cairo Date: Tue, 17 Dec 2024 16:00:51 +0000 Subject: [PATCH] Add an assertion failure if the channel's closeFuture is failed --- Sources/NIOCore/AsyncChannel/AsyncChannel.swift | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Sources/NIOCore/AsyncChannel/AsyncChannel.swift b/Sources/NIOCore/AsyncChannel/AsyncChannel.swift index 74fdd53dcb..105862576d 100644 --- a/Sources/NIOCore/AsyncChannel/AsyncChannel.swift +++ b/Sources/NIOCore/AsyncChannel/AsyncChannel.swift @@ -305,8 +305,20 @@ public struct NIOAsyncChannel: 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 }