Skip to content

fix(net_sync_manager): improve discovery stop handling and auto-connect logic#375

Merged
from2001 merged 2 commits intodevelopfrom
refactor/net_sync_manager-sync-connection
Mar 14, 2026
Merged

fix(net_sync_manager): improve discovery stop handling and auto-connect logic#375
from2001 merged 2 commits intodevelopfrom
refactor/net_sync_manager-sync-connection

Conversation

@from2001
Copy link
Collaborator

This pull request refactors the discovery stopping logic and introduces an auto-connect feature after a server is discovered. The main improvements are better separation of concerns in stopping discovery and automatic connection initiation upon successful discovery.

Discovery logic improvements:

  • Extracted the logic for stopping discovery sockets and threads into a new private method _stop_discovery_internal, improving code reuse and clarity. Now, stop_discovery() calls this internal method after clearing the discovery port, ensuring that the auto-restart mechanism is handled correctly.

Auto-connect enhancement:

  • Added an auto-connect feature in the _discovery_loop method: after a server is discovered, the client updates its internal state, stops the discovery process, and automatically attempts to start a connection if not already running. Errors during this process are logged for easier debugging.

Close #365

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

Refactors the Python net_sync_manager UDP discovery shutdown logic and adds an integrated “discover → apply endpoint → connect” flow to match the behavior expected in Issue #365.

Changes:

  • Extracted discovery shutdown into _stop_discovery_internal() and updated stop_discovery() to clear the auto-restart port before stopping sockets/thread.
  • Enhanced _discovery_loop() to apply discovered server endpoint, stop discovery, and auto-start the client connection when appropriate.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Add self-join guard in _stop_discovery_internal() to prevent
  RuntimeError when called from the discovery thread
- Only update server/dealer_port/sub_port when not already connected
- Retry discovery on start() failure instead of leaving client dead
- Add tests for auto-connect, self-join safety, and failure recovery

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@from2001 from2001 merged commit 0943ac2 into develop Mar 14, 2026
@from2001 from2001 deleted the refactor/net_sync_manager-sync-connection branch March 14, 2026 10:56
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 net_sync_manager: Server IP discovered via discovery is not automatically used for sync connection

2 participants