Skip to content

feat(client): add connection loss detection and reconnection#374

Merged
from2001 merged 4 commits intodevelopfrom
claude/issue-366-20260314-0946
Mar 14, 2026
Merged

feat(client): add connection loss detection and reconnection#374
from2001 merged 4 commits intodevelopfrom
claude/issue-366-20260314-0946

Conversation

@from2001
Copy link
Collaborator

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_error EventHandler — fires with error message on connection loss
  • receive_timeout constructor param (default 30s) — server-silence threshold
  • reconnect_delay constructor 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 discovery
  • Terminal ZMQ errors now escalate to reconnect instead of continuing with broken socket
  • reconnect_count added to stats
  • 4 new tests

Closes #366

Generated with Claude Code

- 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>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_error event plus receive_timeout and reconnect_delay configuration 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_count stat.

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.

@from2001
Copy link
Collaborator Author

@codex Review this PR.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 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".

@from2001 from2001 merged commit 83bae1d into develop Mar 14, 2026
@from2001 from2001 deleted the claude/issue-366-20260314-0946 branch March 14, 2026 10:32
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.

Python client (net_sync_manager) lacks connection loss detection and reconnection

2 participants