feat(client): add connection loss detection and reconnection#374
feat(client): add connection loss detection and reconnection#374
Conversation
- Add on_connection_error EventHandler fired when connection is lost - Add receive_timeout parameter (default 30s) for server-silence detection: silence exceeding the threshold triggers reconnect scheduling - Add reconnect_delay parameter (default 5s) for time before reconnect attempt - Add _trigger_reconnect(): resets client-ready state, stops discovery, fires on_connection_error, and schedules socket teardown/recreation - Add _perform_socket_reconnect(): tears down and recreates ZMQ sockets, rebuilds the poller in the receive loop, and auto-restarts discovery if start_discovery() was previously called - Propagate terminal ZMQ errors (ETERM/ENOTSOCK) from SUB/DEALER drain loops to the reconnect flow instead of silently continuing - Store discovery port in start_discovery(); stop_discovery() clears it to prevent auto-restart (matching user intent) - Add reconnect_count to stats dict - Add 4 tests: event handler presence, constructor params, silence timeout triggering on_connection_error, and stats key Closes #366 Co-authored-by: Masahiro Yamaguchi <from2001@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds connection-loss detection and automatic reconnection behavior to the Python NetSync client (net_sync_manager) to align it more closely with the Unity/C# client’s resiliency flow (Issue #366).
Changes:
- Introduces
on_connection_errorevent plusreceive_timeoutandreconnect_delayconfiguration knobs. - Adds reconnect scheduling/execution logic in the receive loop, including escalation on terminal ZMQ errors.
- Persists discovery port to allow UDP discovery to auto-restart after reconnect; adds tests and
reconnect_countstat.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| STYLY-NetSync-Server/src/styly_netsync/client.py | Implements reconnect state, silence detection, terminal ZMQ error escalation, discovery auto-restart, and new diagnostics stat. |
| STYLY-NetSync-Server/tests/test_python_client.py | Adds tests validating new event handler, parameters, silence-triggered error, and stats key presence. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@codex Review this PR. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 47bccc8549
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Implements connection loss detection and automatic reconnection for the Python client (
net_sync_manager), closing the gap with the C# Unity client.Changes
on_connection_errorEventHandler — fires with error message on connection lossreceive_timeoutconstructor param (default 30s) — server-silence thresholdreconnect_delayconstructor param (default 5s) — delay before reconnect attempt_trigger_reconnect()— resets state, fires event, schedules socket teardown_perform_socket_reconnect()— tears down + recreates sockets, auto-restarts discoveryreconnect_countadded to statsCloses #366
Generated with Claude Code