@@ -46,9 +46,9 @@ unlessClosed ctx
4646 unless (isClosed state) body
4747 where
4848 resetStream e = do
49+ closed ctx strm (ResetByMe e)
4950 let rst = resetFrame InternalError streamNumber
5051 connSendAll rst
51− closed ctx strm (ResetByMe e)
5252
5353checkWindowSize :: TVar WindowSize -> TVar WindowSize -> PriorityTree Output -> Output -> Priority -> (WindowSize -> IO ()) -> IO ()
5454checkWindowSize connWindow strmWindow outQ out pri body = do
@@ -102,8 +102,13 @@ frameSender ctx@Context{outputQ,connectionWindow,wait}
102102 Next datPayloadLen mnext <- fillResponseBodyGetNext conn ii datPayloadOff lim rsp
103103 fillDataHeaderSend strm total datPayloadLen mnext pri
104104 else do
105− bufferIO connWriteBuffer total connSendAll
105+ -- Some implementation send the next request
106+ -- immediately after receiving end of stream
107+ -- even IP packets of the tail portion of DATA frame
108+ -- is not received. So, decrease the concurrency counter
109+ -- first.
106110 closed ctx strm Finished
111+ bufferIO connWriteBuffer total connSendAll
107112 Persist sq tvar -> do
108113 let datPayloadOff = total + frameHeaderLength
109114 Next datPayloadLen mnext <- fillStreamBodyGetNext conn datPayloadOff lim sq tvar
@@ -155,12 +160,20 @@ frameSender ctx@Context{outputQ,connectionWindow,wait}
155160 CFinish -> setEndStream defaultFlags
156161 _ -> defaultFlags
157162 fillFrameHeader FrameData datPayloadLen sid flag buf
163+ -- Some implementation send the next request
164+ -- immediately after receiving end of stream
165+ -- even IP packets of the tail portion of DATA frame
166+ -- is not received. So, decrease the concurrency counter
167+ -- first.
168+ case mnext of
169+ CFinish -> closed ctx strm Finished
170+ _ -> return ()
158171 bufferIO connWriteBuffer total connSendAll
159172 atomically $ do
160173 modifyTVar' connectionWindow (subtract datPayloadLen)
161174 modifyTVar' (streamWindow strm) (subtract datPayloadLen)
162175 case mnext of
163− CFinish -> closed ctx strm Finished
176+ CFinish -> return ()
164177 CNext next -> enqueue outputQ (ONext strm next) pri
165178 CNone -> return ()
166179