Skip to content

Commit

Permalink
Fixed handshake query delay
Browse files Browse the repository at this point in the history
After handshake query the responder side is supposed to close the
connection after 20s.  We used wrong `threadDelay` function, and it
waited only 20μs instead.
  • Loading branch information
coot committed Jun 20, 2023
1 parent 10ea6f1 commit 26f4824
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ makeConnectionHandler muxTracer singMuxMode
atomically $ writePromise (Right HandshakeConnectionQuery)
traceWith tracer $ TrHandshakeQuery vMap
-- Wait 20s for client to receive response, who should close the connection.
threadDelay 20
threadDelay handshake_QUERY_SHUTDOWN_DELAY



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Ouroboros.Network.Protocol.Handshake
, HandshakeResult (..)
, RefuseReason (..)
, Accept (..)
, handshake_QUERY_SHUTDOWN_DELAY
) where

import Control.Monad.Class.MonadAsync
Expand Down Expand Up @@ -182,3 +183,9 @@ runHandshakeServer bearer
haTimeLimits
(fromChannel (muxBearerAsChannel bearer handshakeProtocolNum ResponderDir))
(handshakeServerPeer haVersionDataCodec haAcceptVersion haQueryVersion versions))

-- | A 20s delay after query result was send back, before we close the
-- connection. After that delay we close the connection.
--
handshake_QUERY_SHUTDOWN_DELAY :: DiffTime
handshake_QUERY_SHUTDOWN_DELAY = 20
4 changes: 2 additions & 2 deletions ouroboros-network-framework/src/Ouroboros/Network/Socket.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ module Ouroboros.Network.Socket
, sockAddrFamily
) where

import Control.Concurrent (threadDelay)
import Control.Concurrent.Async
import Control.Concurrent.Class.MonadSTM.Strict
import Control.Exception (SomeException (..))
Expand All @@ -82,6 +81,7 @@ import qualified Codec.CBOR.Term as CBOR
import Control.Monad (unless, when)
import Control.Monad.Class.MonadThrow
import Control.Monad.Class.MonadTime.SI
import Control.Monad.Class.MonadTimer.SI
import qualified Control.Monad.STM as STM
import qualified Data.ByteString.Lazy as BL
import Data.Hashable
Expand Down Expand Up @@ -504,7 +504,7 @@ beginConnection makeBearer muxTracer handshakeTracer handshakeCodec handshakeTim
Right (HandshakeQueryResult _vMap) -> do
traceWith muxTracer' Mx.MuxTraceHandshakeServerEnd
-- Wait 20s for client to receive response, who should close the connection.
threadDelay 20
threadDelay handshake_QUERY_SHUTDOWN_DELAY

RejectConnection st' _peerid -> pure $ Server.Reject st'

Expand Down

0 comments on commit 26f4824

Please sign in to comment.