Skip to content

Session takeover rejects reconnection with DUPLICATE_SESSION_CONNECTION despite incremented sessionVerId #492

Description

@pedrosakuma

Problem

When trading-host restarts and attempts to reconnect with an incremented sessionVerId, matching-platform rejects with DUPLICATE_SESSION_CONNECTION instead of allowing session takeover.

Expected Behavior

Per FIXP spec, when a client reconnects with a higher sessionVerId than the previous connection:

  1. TryForceTakeOver() should detect verId > lastRecordedVerId
  2. Old session should be evicted
  3. New session should be established
  4. Orders should remain valid on the exchange

Actual Behavior

Evidence

# Trading-host snapshot shows verId=2
cat /var/lib/b3trading/entrypoint-state/FIRM01/snapshot.json
{"SessionVerId":2,...}

# Matching-platform rejects reconnection
Negotiate failed: DuplicateConnection
FixpGateway disconnected, will retry in 5000ms

No "taking over sessionId" message appears in matching logs.

Impact

  • Trading-host cannot reconnect to matching after restart (unless matching also restarts)
  • Orders appear Working in trading-host API but may not be in exchange book
  • Breaks session resilience for production scenarios

Root Cause Analysis Needed

  1. Is trading-host actually sending incremented sessionVerId? (Add logging)
  2. Is TryForceTakeOver() being called at all?
  3. What verId comparison is happening in SessionClaimRegistry?
  4. Is PR fix(#488): session takeover on reconnect + responsive heartbeat defaults #491 code actually in the running image?

Files to Investigate

  • src/B3.Exchange.Gateway/SessionClaimRegistry.cs - TryForceTakeOver logic
  • src/B3.Exchange.Gateway/FixpSession.Negotiate.cs - Session takeover trigger
  • src/B3.Exchange.Gateway/FixpSessionManager.cs - Session lifecycle

Reproduction

# Clean start
docker compose down -v && docker compose up -d

# Send order, verify in book
# ... via frontend ...

# Restart only trading-host
docker compose restart trading-host

# Observe: DUPLICATE_SESSION_CONNECTION errors in trading-host logs
# Observe: No "taking over" in matching-platform logs

Related

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