Skip to content

Commit

Permalink
Propagate exceptions to client
Browse files Browse the repository at this point in the history
Also throw an exception if one of the worker threads terminates before
the client has received a response.
  • Loading branch information
pcapriotti committed Dec 10, 2021
1 parent b508ea5 commit 3c269f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
17 changes: 9 additions & 8 deletions Network/HTTP2/Client/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

module Network.HTTP2.Client.Run where

import Control.Concurrent.Async
import Control.Concurrent
import qualified Control.Exception as E
import Data.IORef (writeIORef)
Expand All @@ -24,15 +25,15 @@ run ClientConfig{..} conf@Config{..} client = do
clientInfo <- newClientInfo scheme authority cacheLimit
ctx <- newContext clientInfo
mgr <- start confTimeoutManager
let runBackgroundThreads = do
race_
(frameReceiver ctx confReadN)
(frameSender ctx conf mgr)
E.throwIO (ConnectionError ProtocolError "connection terminated")
exchangeSettings conf ctx
tid0 <- forkIO $ frameReceiver ctx confReadN
-- fixme: if frameSender is terminated but the main thread is alive,
-- what will happen?
tid1 <- forkIO $ frameSender ctx conf mgr
client (sendRequest ctx scheme authority) `E.finally` do
stop mgr
killThread tid0
killThread tid1
fmap (either id id) $
race runBackgroundThreads (client (sendRequest ctx scheme authority))
`E.finally` stop mgr

sendRequest :: Context -> Scheme -> Authority -> Request -> (Response -> IO a) -> IO a
sendRequest ctx@Context{..} scheme auth (Request req) processResponse = do
Expand Down
1 change: 1 addition & 0 deletions http2.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ Library
Network.HTTP2.Server.Worker
Build-Depends: base >= 4.9 && < 5
, array
, async
, bytestring >= 0.10
, case-insensitive
, containers >= 0.5
Expand Down

0 comments on commit 3c269f1

Please sign in to comment.