@@ -2292,7 +2292,7 @@ after action (Stream step state) = Stream step' state
22922292-- Error constructor in step.
22932293--
22942294-- | Run a side effect whenever the stream aborts due to an exception. The
2295−-- exception is not caught simply rethrown.
2295+-- exception is not caught, simply rethrown.
22962296{-# INLINE_NORMAL onException #-}
22972297onException :: MonadCatch m => m b -> Stream m a -> Stream m a
22982298onException action (Stream step state) = Stream step' state
@@ -2311,14 +2311,15 @@ onException action (Stream step state) = Stream step' state
23112311-- exception.
23122312{-# INLINE finally #-}
23132313finally :: MonadCatch m => m b -> Stream m a -> Stream m a
2314−finally action xs = after action $ onException action xs
2314+-- finally action xs = after action $ onException action xs
2315+finally action xs = bracket (return ()) (\_ -> action) (const xs)
23152316
23162317-- XXX bracket is like concatMap, it generates a stream and then flattens it.
23172318-- Like concatMap it has 10x worse performance compared to linear fused
23182319-- compositions.
23192320--
23202321-- | Run the first action before the stream starts and remember its output,
2321−-- generate a stream using the output, run the second action using the
2322+-- generate a stream using the output, run the second action providing the
23222323-- remembered value as an argument whenever the stream ends normally or due to
23232324-- an exception.
23242325{-# INLINE_NORMAL bracket #-}