Skip to content

feat(schema): expose stream writer close signal#1133

Open
Zhang-986 wants to merge 1 commit into
cloudwego:mainfrom
Zhang-986:codex/streamwriter-closed-signal
Open

feat(schema): expose stream writer close signal#1133
Zhang-986 wants to merge 1 commit into
cloudwego:mainfrom
Zhang-986:codex/streamwriter-closed-signal

Conversation

@Zhang-986

Copy link
Copy Markdown
Contributor

What type of PR is this?

feat

Check the PR title.

  • This PR title match the format: (optional scope):
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Attach the PR updating the user documentation if the current PR requires user awareness at the usage level.

More detailed description

This exposes the existing receiver-close notification on StreamWriter.

Problem:
A stream producer can currently observe reader closure only when Send returns closed=true. If the producer is blocked outside Send (for example reading a stalled SSE/network stream), it cannot observe that the consumer has called StreamReader.Close(), so the producer goroutine and upstream connection may remain alive until an external context cancels.

Root cause:
The stream already has an internal closed channel closed by closeRecv, but StreamWriter does not expose it.

Change:
Add StreamWriter.Closed() <-chan struct{} so producers can select on receiver closure and cancel blocked upstream work.

Scope:
This only exposes the existing close signal. It does not change Send, Close, buffering, copy, merge, or automatic-close behavior.

Which issue(s) this PR fixes:

Fixes #1068

Test

  • go test ./schema -run TestStreamWriterClosedClosesWhenReaderCloses -count=1
  • go test ./schema
  • go test ./... -count=1
  • git diff --check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

proposal: expose consumer-close notification on StreamWriter (Closed() <-chan struct{}) — producers blocked outside Send cannot observe reader close

1 participant