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

NIO's (Async)Channel should have a close API that doesn't throw if the Channel is already closed #3061

Open
weissi opened this issue Jan 15, 2025 · 2 comments

Comments

@weissi
Copy link
Member

weissi commented Jan 15, 2025

In many -- likely the vast majority of -- cases, closing a(n) (Async)Channel may raise ChannelError.alreadyClosed. That's because the Channel can also be closed from the network side, so it's gonna be racy.

NIO should provide smth like

extension Channel {
   func close(ignoreAlreadyClosed: Bool) async throws {
       do {
            try await self.close()
       } catch let error as ChannelError, error == .alreadyClosed, ignoreAlreadyClosed {
           () // ignore
       } catch {
           throw error
       }
    }
}

or a similar API. And we should steer users towards using that by default.

@FranzBusch
Copy link
Member

This already exist on the NIOAsyncChannel in the form of executeThenClose which ignores .alreadyClosed errors.

@weissi
Copy link
Member Author

weissi commented Jan 15, 2025

Cool, then we should just document that and also add it to Channel. Once we settle on an API, this can become a #good-first-issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants