Skip to content

Commit

Permalink
Configurable inbound-governor idle timeout
Browse files Browse the repository at this point in the history
For local connections the inbound governor should not force the idleness
timeout.  Some clients relay letting the connection idle after it was
negotiated and before any mini-protocol is started.

We keep the connection manager idle timeout, this is only used for
outbound connections, and thus not related to `node-to-client` protocol.
  • Loading branch information
coot committed Jun 28, 2022
1 parent a95be8e commit 7c8931c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ouroboros-network-framework/demo/connection-manager.hs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ withBidirectionalConnectionManager snocket socket
serverInboundGovernorTracer = ("inbound-governor",) `contramap` debugTracer,
serverConnectionLimits = AcceptedConnectionsLimit maxBound maxBound 0,
serverConnectionManager = connectionManager,
serverInboundIdleTimeout = protocolIdleTimeout,
serverInboundIdleTimeout = Just protocolIdleTimeout,
serverControlChannel = inbgovControlChannel,
serverObservableStateVar = observableStateVar
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ inboundGovernor :: forall (muxMode :: MuxMode) socket peerAddr versionNumber m a
=> Tracer m (RemoteTransitionTrace peerAddr)
-> Tracer m (InboundGovernorTrace peerAddr)
-> ServerControlChannel muxMode peerAddr ByteString m a b
-> DiffTime -- protocol idle timeout
-> Maybe DiffTime -- protocol idle timeout
-> MuxConnectionManager muxMode socket peerAddr
versionNumber ByteString m a b
-> StrictTVar m InboundGovernorObservableState
Expand Down Expand Up @@ -242,11 +242,13 @@ inboundGovernor trTracer tracer serverControlChannel inboundIdleTimeout
Nothing -> return Nothing

Just csCompletionMap -> do
v <- registerDelay inboundIdleTimeout
mv <- traverse registerDelay inboundIdleTimeout
let -- initial state is 'RemoteIdle', if the remote end will not
-- start any responders this will unregister the inbound side.
csRemoteState :: RemoteState m
csRemoteState = RemoteIdle (LazySTM.readTVar v >>= check)
csRemoteState = RemoteIdle (case mv of
Nothing -> retry
Just v -> LazySTM.readTVar v >>= check)

connState = ConnectionState {
csMux,
Expand Down Expand Up @@ -339,9 +341,11 @@ inboundGovernor trTracer tracer serverControlChannel inboundIdleTimeout
let state' = unregisterConnection connId state
return (Just connId, state')
OperationSuccess {} -> do
v <- registerDelay inboundIdleTimeout
mv <- traverse registerDelay inboundIdleTimeout
let timeoutSTM :: STM m ()
!timeoutSTM = LazySTM.readTVar v >>= check
!timeoutSTM = case mv of
Nothing -> retry
Just v -> LazySTM.readTVar v >>= check

let state' = updateRemoteState connId (RemoteIdle timeoutSTM) state

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ data ServerArguments (muxMode :: MuxMode) socket peerAddr versionNumber bytes m
-- | Time for which all protocols need to be idle to trigger
-- 'DemotedToCold' transition.
--
serverInboundIdleTimeout :: DiffTime,
serverInboundIdleTimeout :: Maybe DiffTime,

-- | Server control var is passed as an argument; this allows to use the
-- server to run and manage responders which needs to be started on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ withBidirectionalConnectionManager name timeouts
WithName name `contramap` inboundTracer, -- InboundGovernorTrace
serverConnectionLimits = acceptedConnLimit,
serverConnectionManager = connectionManager,
serverInboundIdleTimeout = tProtocolIdleTimeout timeouts,
serverInboundIdleTimeout = Just (tProtocolIdleTimeout timeouts),
serverControlChannel = inbgovControlChannel,
serverObservableStateVar = observableStateVar
}
Expand Down
4 changes: 2 additions & 2 deletions ouroboros-network/src/Ouroboros/Network/Diffusion/P2P.hs
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ runM Interfaces
serverTracer = dtLocalServerTracer,
serverTrTracer = nullTracer, -- TODO: issue #3320
serverInboundGovernorTracer = dtLocalInboundGovernorTracer,
serverInboundIdleTimeout = local_PROTOCOL_IDLE_TIMEOUT,
serverInboundIdleTimeout = Nothing,
serverConnectionLimits = localConnectionLimits,
serverConnectionManager = localConnectionManager,
serverControlChannel = localControlChannel,
Expand Down Expand Up @@ -1037,7 +1037,7 @@ runM Interfaces
serverInboundGovernorTracer = dtInboundGovernorTracer,
serverConnectionLimits = daAcceptedConnectionsLimit,
serverConnectionManager = connectionManager,
serverInboundIdleTimeout = daProtocolIdleTimeout,
serverInboundIdleTimeout = Just daProtocolIdleTimeout,
serverControlChannel = controlChannel,
serverObservableStateVar = observableStateVar
})
Expand Down

0 comments on commit 7c8931c

Please sign in to comment.