server: release the session lock when a client disconnects mid-stream - #104
Open
jethac wants to merge 1 commit into
Open
server: release the session lock when a client disconnects mid-stream#104jethac wants to merge 1 commit into
jethac wants to merge 1 commit into
Conversation
`opus_reader.read_pcm()` returns None once the client's opus stream ends, which happens whenever a client goes away mid-session rather than closing cleanly. `opus_loop` then evaluates `pcm.shape[-1]` on None and raises inside the `async with self.lock` block, so the task dies while still holding the session lock. The server does not crash, which is what makes this awkward to diagnose: it keeps serving HTTP and accepting websockets, but every subsequent /api/chat blocks forever waiting for a lock that will never be released. Only a restart clears it. Repro: connect a client, start streaming audio, kill it without closing the socket, then try to connect again. Treat the None as the stream-ended signal it is and return, which unwinds the context manager and frees the lock for the next session.
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.
Problem
opus_reader.read_pcm()returnsNoneonce the client's opus stream ends — which happens whenever a client goes away mid-session rather than closing cleanly.opus_loopthen evaluatespcm.shape[-1]onNoneand raises inside theasync with self.lockblock, so the task dies while still holding the session lock.What makes this awkward to diagnose is that the server does not crash. It keeps serving HTTP and accepting websocket upgrades, but every subsequent
/api/chatblocks forever waiting for a lock that will never be released. Only a restart clears it.Reproduction
Hit this in practice with a robot client on flaky wifi; it also shows up any time a browser tab is closed mid-conversation.
Fix
Treat
Noneas the stream-ended signal it is and return, which unwinds the context manager and frees the lock for the next session. Four lines, no behaviour change on the normal path.Independent of any hardware or quantization work — applies to
mainas-is.