Repository navigation
Conversation
|
Can I get a reviewer for this? |
AndersonBY
left a comment
There was a problem hiding this comment.
Reviewed commit 67ae313. All 21 tests pass on Python 3.12/Linux, and both shutdown entry points work with an established local WebSocket connection. One remaining shutdown case needs attention:
[P2] Handle shutdown while the WebSocket connection is still being established
If close() runs immediately after await start(), or during the WebSocket handshake, the underlying WebSocket disconnect returns early because connected is still false. The client then waits for its connection task without stopping it. The socket can subsequently connect and remain active, leaving close() pending and the HTTP session open until the peer disconnects or another disconnect call occurs.
This was reproduced with the real client and a local WebSocket server, mocking only the signed-response fetch. A second explicit disconnect released the pending close.
The underlying disconnect race predates this PR. This change exposes it through close() and moves HTTP cleanup behind that wait; previously, close() closed HTTP before raising the event-loop RuntimeError.
|
Ty, @samirhvbr can you look into this? If you're able to address the concerns, I am happy to merge and release today. |
Awaiting
client.close()from an ordinary coroutine currently raisesRuntimeError: This event loop is already runningand produces an unawaited-disconnectwarning.disconnect(close_client=True)reaches the same path. This reproduces onmasterat4158e6a(7.0.1) without contacting TikTok:Make async
close()await this client's disconnection and close the HTTP session infinally, instead of calling the synchronous loop-driving_clean_tasks(). Letdisconnect(close_client=True)close the HTTP session directly so it does not recurse throughclose(). This drains the client's WebSocket task and resets its state while leaving the application's loop and unrelated tasks running. The HTTP session is still closed if WebSocket cleanup fails.Update the README and remove the now-obsolete async-close limitation/workarounds from the documentation. Public signatures are unchanged; this PR focuses on these two shutdown entry points.
Validation on macOS / Apple Silicon:
python -m pytest: 21 passed on each of Python 3.10, 3.11, and 3.12..github/workflows/lint.ymlpasses. The changed client module also passes with--disable-error-code unused-ignore. The full-tree command from CONTRIBUTING retains the same two pre-existing unusedtype: ignore[misc]errors in listener decorators that were present before this change.AI assistance: prepared with Codex on behalf of @samirhvbr; the reported reproductions and checks were executed locally.