apple / swift-nio

Event-driven network application framework for high performance protocol servers & clients, non-blocking.
https://swiftpackageindex.com/apple/swift-nio/documentation
Apache License 2.0
7.85k stars 633 forks source link

Throw an appropriate error from the writer when the channel closed #2744

Closed FranzBusch closed 1 week ago

FranzBusch commented 2 weeks ago

Motivation

Currently, when the channel closes and a user tries to write something the writer throws an AlreadyFinished error. This error can also be thrown when calling finish on the writer and then trying to call write again. This makes it hard to distinguish if the thrown error was due to the channel being closed or due to a business logic error in handling the writer.

Modification

This PR finishes the writer with a ChannelError.ioOnClosedChannel if the writer gets finished to due a channel inactive or handler removed.

Result

Users can now distinguish if they did something wrong with the writer or if the channel closed.

FranzBusch commented 2 weeks ago

@swift-server-bot test this please

FranzBusch commented 2 weeks ago

@swift-server-bot test this please

FranzBusch commented 1 week ago

@swift-server-bot test this please