fix Channel writes after close (carry #30) - #75
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes non-deterministic Channel.Write behavior after Channel.Close by ensuring writes performed after the sink is closed consistently return ErrSinkClosed, even when the underlying event channel still has buffer capacity. This aligns Channel sink semantics with the expectations in #29 and carries the earlier work from #30.
Changes:
- Update
Channel.Writeto prioritize the closed signal before attempting a send, while still allowingCloseto unblock a write that is already blocked. - Add regression tests covering (1) write-after-close always returning
ErrSinkClosed, and (2) close unblocking a blocked write.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| channel.go | Adjusts Channel.Write select logic to deterministically return ErrSinkClosed after close and to unblock blocked writers on close. |
| channel_test.go | Adds regression tests for write-after-close determinism and close-unblocks-write behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Ensure Channel.Write returns ErrSinkClosed when called after the channel has been closed, even when the event channel has capacity to accept the event. Keep the close case in the blocking select so that a Write already waiting for a receiver is also unblocked when Close is called. Co-authored-by: Adrián Orive <aorive@ikerlan.es> Signed-off-by: Adrián Orive <aorive@ikerlan.es> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
vvoland
approved these changes
Aug 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ensure Channel.Write returns ErrSinkClosed when called after the channel has been closed, even when the event channel has capacity to accept the event.
Keep the close case in the blocking select so that a Write already waiting for a receiver is also unblocked when Close is called.