Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make protect safer against exceptions in a Pipe value.

Fix an issue reported by Michael Snoyman, where an exception contained
in a `Pipe` value would cause finalizers to be leaked.

This commit introduces an extra monadic step at each `protect` call,
which ensures that any exceptions contained in the continuation thunk
can be captured and rethrown within the `Pipe` monad.
  • Loading branch information...
commit 7bb846ea620f1a2595c45cb4a52b16ff3fe1febd 1 parent 8e09373
Paolo Capriotti authored
Showing with 1 addition and 1 deletion.
  1. +1 −1  Control/Pipe/Common.hs
2  Control/Pipe/Common.hs
@@ -200,7 +200,7 @@ discard :: Monad m => Pipe a b m r
discard = forever await
protect :: Monad m => Finalizer m -> Pipe a b m r -> Pipe a b m r
-protect w = go
+protect w p = M Masked (return $! go p) (`Throw` w)
go (Pure r w') = Pure r (w ++ w')
go (Throw e w') = Throw e (w ++ w')
Please sign in to comment.
Something went wrong with that request. Please try again.