Skip to content

Commit

Permalink
Reliable tracing with Async exceptions
Browse files Browse the repository at this point in the history
In promotedToWarmRemoteImpl (and family), it is possible that the STM action successfully commits, writing a new state to the connVar, but right after an AsyncCancelled is received making us omit the respective transition tracing.
  • Loading branch information
bolt12 committed Oct 12, 2021
1 parent 9478f2a commit 5631f29
Showing 1 changed file with 7 additions and 4 deletions.
Expand Up @@ -1022,12 +1022,13 @@ withConnectionManager ConnectionManagerArguments {
(const $ Connected connId dataFlow handle)
mbTransition)


-- Needs 'mask' in order to guarantee that the traces are logged if the an
-- Async exception lands between the successful STM action and the logging action.
unregisterInboundConnectionImpl
:: StrictTMVar m (ConnectionManagerState peerAddr handle handleError version m)
-> peerAddr
-> m (OperationResult DemotedToColdRemoteTr)
unregisterInboundConnectionImpl stateVar peerAddr = do
unregisterInboundConnectionImpl stateVar peerAddr = mask_ $ do
traceWith tracer (TrUnregisterConnection Inbound peerAddr)
(mbThread, mbTransition, result) <- atomically $ do
state <- readTMVar stateVar
Expand Down Expand Up @@ -1677,7 +1678,7 @@ withConnectionManager ConnectionManagerArguments {
-- @
-- DemotedToCold^{Duplex}_{Local}
-- : OutboundState Duplex
--InboundIdleState^\tau
--OutboundIdleState^\tau
-- @
let connState' = OutboundIdleState connId connThread handle
Duplex
Expand Down Expand Up @@ -1875,6 +1876,8 @@ withConnectionManager ConnectionManagerArguments {
return (OperationSuccess a)


-- Needs 'mask' in order to guarantee that the traces are logged if the an
-- Async exception lands between the successful STM action and the logging action.
promotedToWarmRemoteImpl
:: StrictTMVar m (ConnectionManagerState peerAddr handle handleError version m)
-> peerAddr
Expand Down Expand Up @@ -2043,7 +2046,7 @@ withConnectionManager ConnectionManagerArguments {
-- - set the state to 'TerminatedState'
traverse_ cancel pruneMap

_ -> return ()
_ -> pure ()
return (abstractState . fromState <$> fst result)


Expand Down

0 comments on commit 5631f29

Please sign in to comment.