Repository navigation
Conversation
- Reconnect a working connection silently before reporting it as lost, emit 'connection.interrupted' instead. Server restart is still reported as closed right away. - Count receive timeouts instead of measuring wall-clock time, so a host holding the GIL does not make the connection look dead. - Block SIGPIPE in the websocket thread, some hosts reset it to the default action which terminates the process. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BigRoy
left a comment
There was a problem hiding this comment.
Checked it against the ayon-core hub, the logic matches apart from _wait. One real issue (logout), the rest is small.
| # by a proxy or a network hiccup. Report it as lost only if | ||
| # reconnecting fails. Server restart is reported right away, the | ||
| # restart overlay is hidden only by 'connection.opened'. | ||
| if received_message and not state.server_is_restarting: |
There was a problem hiding this comment.
Core's hub has no reconnect()/reauthenticate(), so this branch now also catches logout: reset_token() -> reauthenticate() -> reconnect() emits connection.interrupted, leaves the state None and never reports connection.closed (develop: closed, state False).
Only reconnecting silently when there is a token fixes it, existing tests still pass. Worth a regression test in test_event_hub_lifecycle.py (con.reset_token() -> expect connection.closed).
| if received_message and not state.server_is_restarting: | |
| if ( | |
| received_message | |
| and not state.server_is_restarting | |
| and self._connection.access_token | |
| ): |
| Internal topics: | ||
| - 'connection.opened' first message received after (re)connection. | ||
| - 'connection.closed' connection was lost or could not be created. | ||
| - 'connection.interrupted' connection was lost and is reconnected |
There was a problem hiding this comment.
Listeners that resync on connection.closed won't see short drops anymore, core needed a follow-up for its folders cache for exactly this (also listens to connection.interrupted now). Maybe say here and in the changelog that it should be handled like closed by anything caching server data.
| # Python ignores it, but some hosts reset it to the default | ||
| # action which terminates the process (e.g. Silhouette on Linux). | ||
| if hasattr(signal, "pthread_sigmask"): | ||
| signal.pthread_sigmask(signal.SIG_BLOCK, {signal.SIGPIPE}) |
There was a problem hiding this comment.
Callbacks run in this thread, so threads and subprocesses started from a callback inherit the blocked SIGPIPE too (checked on Rocky 9: yes | head started from the hub thread prints Broken pipe instead of exiting quietly). Low risk and core does the same, maybe just a line in the Warnings of the class docstring.
| assert fake_ws.pings == 2 | ||
|
|
||
|
|
||
| def test_timeouts_are_counted_not_measured(run_hub, monkeypatch): |
There was a problem hiding this comment.
This one also passes against develop's wall-clock code, so it doesn't guard the change. Jumping time.monotonic forward a few minutes on each TIMEOUT (like a GIL stall) would make the old code report closed. Patching both constants to their default values doesn't do anything either.
- Reconnect silently only while there is a token, logout closed the connection and was reported as 'connection.interrupted' with unknown state instead of 'connection.closed'. - Say in docstring that 'connection.interrupted' should be handled like 'connection.closed' by anything caching server data. - Timeout counting test now simulates GIL stall with a jumping clock, it passed with wall-clock based detection before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Changelog Description
Port websocket fixes from the ayon-core event hub (
ayon_core/tools/common_models/websocket.py) toEventHub, so both implementations behave the same.New
connection.interruptedevent is emitted when a working connection drops and is reconnected silently. Anything that caches server data and resyncs onconnection.closedshould handleconnection.interruptedthe same way.Additional info
connection.interrupted(EventHub.TOPIC_CONNECTION_INTERRUPTED) and reconnects.connection.openedis emitted once reconnected,connection.closedonly if reconnecting fails. Server restart and logout (token removed) are still reported as closed right away.time.monotonic(). The thread might not run for a long time while messages are waiting in the socket, so wall-clock time made a stalled-but-alive connection look dead.Behavior change: listeners of
connection.closedwon't receive short drops anymore, andreconnect()called on an open connection emitsconnection.interruptedinstead ofconnection.closed.Testing notes:
pytest tests/test_event_hub_ping.py tests/test_event_hub_lifecycle.pyreset_token()) with the hub connected and checkconnection.closedis emitted.