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

Properly close streams #104

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion Network/HTTP2/H2/Context.hs
Expand Up @@ -175,7 +175,20 @@ setPeerStreamID ctx sid = writeIORef (peerStreamId ctx) sid

{-# INLINE setStreamState #-}
setStreamState :: Context -> Stream -> StreamState -> IO ()
setStreamState _ Stream{streamState} val = writeIORef streamState val
setStreamState _ Stream{streamState} newState = do
oldState <- readIORef streamState
case (oldState, newState) of
(Open _ (Body q _ _ _), Open _ (Body q' _ _ _)) | q == q' ->
-- The stream stays open with the same body; nothing to do
return ()
(Open _ (Body q _ _ _), _) ->
-- The stream is either closed, or is open with a /new/ body
-- We need to close the old queue so that any reads from it won't block
atomically $ writeTQueue q $ Left $ toException ConnectionIsClosed
_otherwise ->
-- The stream wasn't open to start with; nothing to do
return ()
writeIORef streamState newState

opened :: Context -> Stream -> IO ()
opened ctx strm = setStreamState ctx strm (Open Nothing JustOpened)
Expand Down