@@ -232,9 +232,12 @@ control FrameGoAway _ _ Context{controlQ} = do
232232
233233control FrameWindowUpdate header bs Context{connectionWindow} = do
234234 WindowUpdateFrame n <- guardIt $ decodeWindowUpdateFrame header bs
235− !w <- (n +) <$> atomically (readTVar connectionWindow)
235+ !w <- atomically $ do
236+ w0 <- readTVar connectionWindow
237+ let w1 = w0 + n
238+ writeTVar connectionWindow w1
239+ return w1
236240 when (isWindowOverflow w) $ E.throwIO $ ConnectionError FlowControlError "control window should be less than 2^31"
237− atomically $ writeTVar connectionWindow w
238241 return True
239242
240243control _ _ _ _ =
@@ -336,10 +339,13 @@ stream FrameContinuation FrameHeader{flags} frag ctx (Open (Continued rfrags siz
336339
337340stream FrameWindowUpdate header@FrameHeader{streamId} bs _ s Stream{streamWindow} = do
338341 WindowUpdateFrame n <- guardIt $ decodeWindowUpdateFrame header bs
339− !w <- (n +) <$> atomically (readTVar streamWindow)
342+ !w <- atomically $ do
343+ w0 <- readTVar streamWindow
344+ let w1 = w0 + n
345+ writeTVar streamWindow w1
346+ return w1
340347 when (isWindowOverflow w) $
341348 E.throwIO $ StreamError FlowControlError streamId
342− atomically $ writeTVar streamWindow w
343349 return s
344350
345351stream FrameRSTStream header bs ctx _ strm = do