Skip to content

fix: send explicit protocol error on session race condition (#8)#16

Open
rafabd1 wants to merge 1 commit intomainfrom
fix/issue-8-session-race-condition
Open

fix: send explicit protocol error on session race condition (#8)#16
rafabd1 wants to merge 1 commit intomainfrom
fix/issue-8-session-race-condition

Conversation

@rafabd1
Copy link
Owner

@rafabd1 rafabd1 commented Mar 14, 2026

Fix: Send explicit protocol error on session race condition

Closes #8

Problem

When a peer tried to connect to a node that already had an active session, handle_incoming silently returned Ok(()) without sending any response. The initiator would hang indefinitely waiting for a handshake ACK that never came.

Solution

  • Added ProtocolError wire type ({t: "err", code: "...", msg: "..."})
  • When a session is already active, handle_incoming now sends an error frame with code: "session_active" before closing the connection
  • The initiator (initiate_session) now checks for protocol errors in the response frame before attempting to parse it as a handshake ACK
  • Maps error codes to user-friendly messages (e.g., "Peer already has an active session")

Security considerations

  • The error frame reveals minimal information (only that a session is active, not any identity details)
  • No key material is exchanged in the error path

This PR was generated with Oz.

- When handle_incoming rejects because a session is already active,
  send a ProtocolError frame {t:'err', code:'session_active'} to the
  initiator instead of silently dropping the connection
- Initiator now checks for protocol errors before parsing ACK and
  surfaces a user-friendly message
- Logged rejected connection attempts for visibility

Co-Authored-By: Oz <oz-agent@warp.dev>
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.

Session establishment race condition

1 participant