Skip to content

fix: xAI streaming can deadlock permanently on client disconnect or cancellation#371

Closed
sam-saffron-jarvis wants to merge 1 commit intoSamSaffron:mainfrom
sam-saffron-jarvis:feat/codereview-81e8051e
Closed

fix: xAI streaming can deadlock permanently on client disconnect or cancellation#371
sam-saffron-jarvis wants to merge 1 commit intoSamSaffron:mainfrom
sam-saffron-jarvis:feat/codereview-81e8051e

Conversation

@sam-saffron-jarvis
Copy link
Copy Markdown
Contributor

What

  • make both xAI streaming paths use a context-aware event emitter instead of plain blocking channel sends
  • return early when the stream context is cancelled while emitting text, tool execution, usage, or done events
  • add regression tests covering both the standard chat stream and the search/responses stream when the consumer stops draining events

Why

If the caller disconnects or abandons the stream, the 16-event buffer created by newEventStream can fill up. The old plain events <- ... sends in internal/llm/xai.go would then block forever, which prevented channelStream.Close() from finishing and left the xAI response body/request wedged. Making those sends context-aware lets cancellation unwind the producer goroutine cleanly.

@SamSaffron SamSaffron closed this Apr 15, 2026
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.

2 participants