Skip to content

fix: apply receive_timeout to WebSocket reads - #515

Merged
rany2 merged 1 commit into
rany2:masterfrom
uzunenes:fix-ws-receive-timeout
Nov 29, 2026
Merged

rany2 merged 1 commit into
rany2:masterfrom
uzunenes:fix-ws-receive-timeout

Conversation

@uzunenes

@uzunenes uzunenes commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

receive_timeout only sets sock_read on the session. Since aiohttp 3.10, ws_connect() replaces that with its own receive timeout (none by default) after the upgrade, so if the service goes quiet without closing the socket, stream()/save() never return. We had a batch job stuck for ~19 hours on this.

This passes the same timeout to ws_connect() (ClientWSTimeout on aiohttp >= 3.11, receive_timeout= on older versions).

This is #486 again, rebased on current master (bd44c1d, 7.3.1); I closed #486 myself after a quiet spell and the fork was gone, so it could not be reopened. The recent stream_sync fix (bd44c1d) handles errors raised in the worker thread; this one makes sure an error is raised in the first place. Re-tested today with edge-tts 7.3.1 + aiohttp 3.14.5 against a local WebSocket server that accepts and then stays silent, receive_timeout=3:

  • master: still waiting after 20 s (stopped by an outer guard)
  • this branch: TimeoutError after 3.0 s

Earlier matrix (from #486): silent server hangs before on aiohttp 3.9.5–3.14.3 and raises after 3 s with the fix; a server that stops mid-stream hangs before on 3.10.11–3.14.3 and raises with the fix; a slow but alive server (2 s gaps) works before and after. Normal synthesis against the real service is unchanged. lint.sh and format.sh are clean (pylint 10.00/10, mypy clean, black/isort unchanged).

Since aiohttp 3.10, ws_connect() replaces the session's sock_read timeout with
its own receive timeout (none by default) once the connection is upgraded, so a
service that goes quiet without closing the socket makes stream()/save() hang
forever. Pass the same timeout to ws_connect() (ClientWSTimeout on aiohttp >=
3.11, receive_timeout= on older versions).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uzunenes

Copy link
Copy Markdown
Contributor Author

Gentle ping on this one. It makes receive_timeout apply to WebSocket reads, so a stalled connection raises instead of hanging forever. The branch has no conflicts with master. Happy to adjust the approach or add a test if that helps the review.

@rany2
rany2 merged commit 4e17d76 into rany2:master Nov 29, 2026
@rany2

rany2 commented Nov 29, 2026

Copy link
Copy Markdown
Owner

Thanks! This will be part of the next release.

uzunenes added a commit to uzunenes/uzunenes.github.io that referenced this pull request Nov 29, 2026
Covers the receive_timeout bug fixed in rany2/edge-tts#515 (merged on
master as 4e17d767): aiohttp 3.10+ clears the protocol read timeout after
the WebSocket upgrade unless a WebSocket timeout is passed to ws_connect().

Assets: local WebSocket verification script (verify_edge_tts_ws_timeout.py).
about.md: one line under Open source.
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