Skip to content

fix Channel writes after close (carry #30) - #75

Merged
thaJeztah merged 1 commit into
docker:mainfrom
thaJeztah:carry_pr_30
Aug 28, 2026
Merged

fix Channel writes after close (carry #30)#75
thaJeztah merged 1 commit into
docker:mainfrom
thaJeztah:carry_pr_30

Conversation

@thaJeztah

Copy link
Copy Markdown
Member

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Write to prioritize the closed signal before attempting a send, while still allowing Close to 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.

Comment thread channel_test.go
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>
@thaJeztah
thaJeztah merged commit 5d135c8 into docker:main Aug 28, 2026
13 checks passed
@thaJeztah
thaJeztah deleted the carry_pr_30 branch August 28, 2026 13:48
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

Successfully merging this pull request may close these issues.

Channel.Write after Channel.Close

4 participants