fix: Disconnect peers on handshake failure#441
fix: Disconnect peers on handshake failure#441mergify[bot] merged 1 commit intosigp:release-v0.3.0from
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR improves the mismatched_networks_handshake_failed test by adding verification that peers are properly disconnected when handshake fails due to network mismatch. The existing disconnection functionality was already working correctly - this change adds test coverage to verify the behavior.
- Adds tracking of connection close events for both local and remote peers
- Extends the test loop condition to wait for both handshake failures and disconnections
- Adds explicit assertions to verify both handshake failures and disconnections occurred
|
I think this works because at some point there is a keepalive timeout as nothing is being sent anymore: The test takes 10 seconds. So I think #438 is actually valid. We should modify this test to ensure the disconnection reason is correct (if possible), or ensure that the disconnection is soon after handshake failure. |
870bad0 to
23c281a
Compare
|
Sorry, can you please rebase this from |
|
It seems to be good to be merged into |
c699312 to
46cdf05
Compare
- Add explicit peer disconnection in network layer when handshake fails - Update CLAUDE.md with testing best practices about not simulating production behavior in tests - The existing handshake test validates failure detection; disconnection behavior will be tested through integration tests that use the full network stack
46cdf05 to
8a3dd50
Compare
sigp#438 - **Add explicit peer disconnection**: When a handshake fails (e.g., due to network mismatch), the network layer now explicitly disconnects the peer via `disconnect_peer_id()` - **Improve disconnection timing**: Instead of relying on keep-alive timeouts (~10 seconds), peers are disconnected immediately upon handshake failure - **Preserve existing test**: The handshake test continues to validate failure detection; disconnection behavior will be naturally tested through integration tests that use the full network stack - **Add testing best practices**: Updated CLAUDE.md with guidance about not simulating production behavior in tests
sigp#438 - **Add explicit peer disconnection**: When a handshake fails (e.g., due to network mismatch), the network layer now explicitly disconnects the peer via `disconnect_peer_id()` - **Improve disconnection timing**: Instead of relying on keep-alive timeouts (~10 seconds), peers are disconnected immediately upon handshake failure - **Preserve existing test**: The handshake test continues to validate failure detection; disconnection behavior will be naturally tested through integration tests that use the full network stack - **Add testing best practices**: Updated CLAUDE.md with guidance about not simulating production behavior in tests
Issue Addressed
#438
Proposed Changes
disconnect_peer_id()Technical Details
The change is made in
Network::handle_handshake_result()where handshake failures are processed. When a handshake fails, we now callself.swarm.disconnect_peer_id(peer_id)to immediately disconnect the peer, rather than waiting for keep-alive timeouts.This ensures faster and more deterministic peer disconnection on handshake failures, improving network behavior and reducing connection overhead.