Skip to content

Session establishment race condition #8

@rafabd1

Description

@rafabd1

In handle_incoming() (session.rs:267-269), if a peer tries to connect while one is already active:

if state.session.lock().await.is_some() {
    return Ok(());  // Silent return, connection not acknowledged
}

This causes:

  1. Connection hangs: The initiator sends HANDSHAKE_INIT and waits for ACK indefinitely
  2. No protocol error: The peer never sends back an error, just closes the stream
  3. User confusion: Both users think they're waiting for a response

Scenario:

  • Alice and Bob already have a session
  • Charlie tries to connect to Alice at the same time Bob sends a message
  • Charlie's HANDSHAKE_INIT is dropped, Charlie hangs
  • Alice sees no indication of the failed connection attempt

Proposed solution:

  • Send an explicit protocol error (e.g., type="err", code="session_active")
  • Or: Support multiple concurrent sessions (complex, but aligns with group chat)
  • Track and log failed connection attempts for user visibility

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions