Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid undefined in client #146

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions Network/HTTP2/Client/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ setup ClientConfig{..} conf@Config{..} = do

runH2 :: Config -> Context -> IO a -> IO a
runH2 conf ctx runClient = do
stopAfter mgr (clientResult <$> race runBackgroundThreads runClient) $ \res ->
stopAfter mgr runAll $ \res ->
closeAllStreams (oddStreamTable ctx) (evenStreamTable ctx) res
where
mgr = threadManager ctx
Expand All @@ -152,9 +152,19 @@ runH2 conf ctx runClient = do
labelMe "H2 runBackgroundThreads"
concurrently_ runReceiver runSender

clientResult :: Either () a -> a
clientResult (Left ()) = undefined -- unreachable
clientResult (Right a) = a
-- Run the background threads and client concurrently. If the client
-- finishes first, cancel the background threads. If the background
-- threads finish first, wait for the client.
runAll = do
withAsync runBackgroundThreads $ \runningBackgroundThreads ->
withAsync runClient $ \runningClient -> do
result <- waitEither runningBackgroundThreads runningClient
case result of
Right clientResult -> do
cancel runningBackgroundThreads
return clientResult
Left () -> do
wait runningClient

sendRequest
:: Config
Expand Down
3 changes: 3 additions & 0 deletions Network/HTTP2/H2/Receiver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ frameReceiver ctx@Context{..} conf@Config{..} = do
loop

sendGoaway se
| Just GoAwayIsSent <- E.fromException se = do
waitCounter0 threadManager
enqueueControl controlQ $ CFinish GoAwayIsSent
| Just ConnectionIsClosed <- E.fromException se = do
waitCounter0 threadManager
enqueueControl controlQ $ CFinish ConnectionIsClosed
Expand Down
Loading