Fix stream keep-alive handling; bump to v1.0.0
Force-close each /stream/{channel_id} response instead of allowing
keep-alive reuse. Jellyfin's SharedHttpStream tuner client was reusing
a pooled keep-alive connection mid-stream from an earlier request and
reading raw MPEG-TS bytes as an HTTP status line, failing with
'Received an invalid status line'.
Also broaden the disconnect exception handling to ConnectionAbortedError
alongside ConnectionResetError.
This commit is contained in:
@@ -42,6 +42,10 @@ async def _handle_stream(request: web.Request) -> web.StreamResponse:
|
||||
raise web.HTTPNotFound(text=f"Unknown channel '{channel_id}'")
|
||||
|
||||
response = web.StreamResponse(status=200, headers={"Content-Type": MPEGTS_CONTENT_TYPE})
|
||||
# A live stream is never meant to be pooled and reused for a later request; some HTTP
|
||||
# clients (e.g. Jellyfin's SharedHttpStream) get fed stale bytes from a dangling
|
||||
# keep-alive connection if we let one linger here. Force a fresh connection every time.
|
||||
response.force_close()
|
||||
await response.prepare(request)
|
||||
|
||||
queue = broadcaster.subscribe()
|
||||
@@ -51,7 +55,7 @@ async def _handle_stream(request: web.Request) -> web.StreamResponse:
|
||||
if chunk is None:
|
||||
break
|
||||
await response.write(chunk)
|
||||
except ConnectionResetError:
|
||||
except (ConnectionResetError, ConnectionAbortedError):
|
||||
logger.debug("Client disconnected from channel '{}'", channel_id)
|
||||
finally:
|
||||
broadcaster.unsubscribe(queue)
|
||||
|
||||
Reference in New Issue
Block a user