Skip to content

Commit

Permalink
Avoid unnecessary empty data frames at end of stream
Browse files Browse the repository at this point in the history
Currently, if a stream terminates with an empty data frame, we will send that
empty data frame even if it is succeeded by trailers that are marked end of
stream. That empty data frame is unnecessary. We should only send it if the
payload length is non-zero and we are not sending trailers.
  • Loading branch information
FinleyMcIlwaine committed Aug 6, 2024
1 parent 94a7d2c commit 9375b0c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Network/HTTP2/H2/Sender.hs
Original file line number Diff line number Diff line change
Expand Up @@ -282,17 +282,23 @@ frameSender
_
reqflush = do
let buf = confWriteBuffer `plusPtr` off
off' = off + frameHeaderLength + datPayloadLen
(mtrailers, flag) <- do
Trailers trailers <- tlrmkr Nothing
if null trailers
then return (Nothing, setEndStream defaultFlags)
else return (Just trailers, defaultFlags)
fillFrameHeader FrameData datPayloadLen streamNumber flag buf
-- Avoid sending an empty data frame before trailers at the end
-- of a stream
off' <-
if datPayloadLen /= 0 || isNothing mtrailers then do
decreaseWindowSize ctx strm datPayloadLen
fillFrameHeader FrameData datPayloadLen streamNumber flag buf
return $ off + frameHeaderLength + datPayloadLen
else
return off
off'' <- handleTrailers mtrailers off'
_ <- sync Nothing
halfClosedLocal ctx strm Finished
decreaseWindowSize ctx strm datPayloadLen
if reqflush
then do
flushN off''
Expand Down

0 comments on commit 9375b0c

Please sign in to comment.