Skip to content

Commit

Permalink
Wait for closeFuture instead of close promise in executeThenClose
Browse files Browse the repository at this point in the history
  • Loading branch information
gjcairo committed Dec 17, 2024
1 parent 2d72ada commit d050010
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
16 changes: 7 additions & 9 deletions Sources/NIOCore/AsyncChannel/AsyncChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,13 @@ public struct NIOAsyncChannel<Inbound: Sendable, Outbound: Sendable>: Sendable {
}
}

do {
self._outbound.finish()
try await self.channel.close().get()
} catch {
if let error = error as? ChannelError, error == .alreadyClosed {
return result
}
throw error
}
self._outbound.finish()
// 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()

return result
}
}
Expand Down
5 changes: 5 additions & 0 deletions Sources/NIOCore/Channel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ public protocol Channel: AnyObject, ChannelOutboundInvoker, _NIOPreconcurrencySe
var allocator: ByteBufferAllocator { get }

/// The `closeFuture` will fire when the `Channel` has been closed.
///
/// - Important: This future will never be failed, as it signals when the channel has been closed, and this action cannot fail.
/// If you are interested in any errors thrown during `close` to diagnose any unclean channel closures, you
/// should instead use the future returned from ``close(mode:file:line:)`` or pass a promise via
/// ``close(mode:promise:)``.
var closeFuture: EventLoopFuture<Void> { get }

/// The `ChannelPipeline` which handles all I/O events and requests associated with this `Channel`.
Expand Down

0 comments on commit d050010

Please sign in to comment.