Skip to content

Commit

Permalink
net-sim: protect from establishing connection twice
Browse files Browse the repository at this point in the history
When we create a connection we set it's state to `SYN_SENT`, before it
is accepted by the other side, we could try to connect again.  In such
case we ought to error.
  • Loading branch information
coot committed Oct 20, 2022
1 parent 1a4c0e2 commit 96584fc
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ouroboros-network-framework/src/Simulation/Network/Snocket.hs
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,10 @@ mkSnocket state tr = Snocket { getLocalAddr
Just Connection { connState = ESTABLISHED } ->
throwSTM (connectedIOError fd_)

Just Connection { connState = SYN_SENT, connProvider }
| connProvider == localAddress ->
throwSTM (connectedIOError fd_)

-- simultaneous open
Just conn@Connection { connState = SYN_SENT } -> do
let conn' = conn { connState = ESTABLISHED }
Expand Down

0 comments on commit 96584fc

Please sign in to comment.