Skip to content

EventHub: Port websocket robustness fixes from ayon-core - #386

Merged
iLLiCiTiT merged 3 commits into
developfrom
bugfix/event-hub-port-core-fixes
Nov 25, 2026
Merged

iLLiCiTiT merged 3 commits into
developfrom
bugfix/event-hub-port-core-fixes

Conversation

@iLLiCiTiT

@iLLiCiTiT iLLiCiTiT commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Changelog Description

Port websocket fixes from the ayon-core event hub (ayon_core/tools/common_models/websocket.py) to EventHub, so both implementations behave the same.

New connection.interrupted event is emitted when a working connection drops and is reconnected silently. Anything that caches server data and resyncs on connection.closed should handle connection.interrupted the same way.

Additional info

  • Silent reconnect: when a working connection is closed (client did not answer server pings because the host held the GIL, proxy, network hiccup), the hub emits new connection.interrupted (EventHub.TOPIC_CONNECTION_INTERRUPTED) and reconnects. connection.opened is emitted once reconnected, connection.closed only if reconnecting fails. Server restart and logout (token removed) are still reported as closed right away.
  • Receive timeouts are counted instead of measured with 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.
  • SIGPIPE is blocked in the websocket thread. Some hosts (e.g. Silhouette on Linux) reset it to the default action which terminates the process when writing to a closed connection.

Behavior change: listeners of connection.closed won't receive short drops anymore, and reconnect() called on an open connection emits connection.interrupted instead of connection.closed.

Testing notes:

  1. pytest tests/test_event_hub_ping.py tests/test_event_hub_lifecycle.py
  2. Connect a tool to the server, kill/restart the server's proxy (or briefly drop network) and check the connection is not reported as lost when it comes back quickly.
  3. Restart the server from the UI and check the restart is still reported right away.
  4. Log out (reset_token()) with the hub connected and check connection.closed is emitted.

- 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>
@iLLiCiTiT iLLiCiTiT added the type: bug Something isn't working label Nov 23, 2026
@iLLiCiTiT iLLiCiTiT self-assigned this Nov 23, 2026
@iLLiCiTiT
iLLiCiTiT requested a review from BigRoy November 23, 2026 13:26

@BigRoy BigRoy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked it against the ayon-core hub, the logic matches apart from _wait. One real issue (logout), the rest is small.

Comment thread ayon_api/events.py Resolved
Comment thread ayon_api/events.py Resolved
Comment thread ayon_api/events.py Resolved
Comment thread tests/test_event_hub_ping.py Resolved
iLLiCiTiT and others added 2 commits November 24, 2026 17:24
- 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>

@BigRoy BigRoy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested against a local server: GIL held 18 s / 60 s, proxy drop, proxy down, logout and server restart all report as described, and events keep arriving after each reconnect.

@iLLiCiTiT
iLLiCiTiT merged commit 911428c into develop Nov 25, 2026
3 checks passed
@iLLiCiTiT
iLLiCiTiT deleted the bugfix/event-hub-port-core-fixes branch November 25, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants