Skip to content

Commit

Permalink
Fix a race condition in demuxing (IO)
Browse files Browse the repository at this point in the history
For 0 length SDUs there was a risk that the responder application
finished before the ingress thread parsed the header and threw an exception.
  • Loading branch information
karknu committed Mar 2, 2020
1 parent d12baa2 commit 0a7ad4c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions network-mux/test/Test/Mux.hs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ smallMiniProtocolLimit = 16*1024

activeTracer :: forall m a. (MonadSay m, Show a) => Tracer m a
activeTracer = nullTracer
--activeTracer = showTracing sayTracer
--activeTracer = showTracing _sayTracer

_sayTracer :: MonadSay m => Tracer m String
_sayTracer = Tracer say
Expand Down Expand Up @@ -835,7 +835,10 @@ prop_demux_sdu a = do

setup state client_w
atomically $ writeTBQueue client_w $ BL.take (isRealLength badSdu) $ encodeInvalidMuxSDU badSdu
atomically $ putTMVar stopVar $ BL.replicate (fromIntegral $ isLength badSdu) 0xa
-- Incase this is an SDU with a payload of 0 byte, we still ask the responder to wait for
-- one byte so that we fail with an exception while parsing the header instead of risk
-- having the responder succed after reading 0 bytes.
atomically $ putTMVar stopVar $ BL.replicate (max (fromIntegral $ isLength badSdu) 1) 0xa

res <- wait said
case res of
Expand Down

0 comments on commit 0a7ad4c

Please sign in to comment.