Gabriella439 / Gabriella439/Haskell-Pipes-Safe-Library

Finalizer not called with some uses of runSafeP and nested pipes

Open
#12 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
27
Forks
22
Avg merge
12d 10h
Merged PRs (30d)
1

Description

I think there was a Haskell-pipes mailing list discussion that I started about this a while back. I will link it if I find it later, I searched for a few moments with out luck. I thought this should be documented for others to reference since it is often hard to search through mailing lists.

The conclusion as I remember it was the problem came down to `C.bracket` in `runSafeT`.

```
runSafeT :: (MonadCatch m, MonadIO m) => SafeT m r -> m r
runSafeT m = C.bracket
(liftIO $ newIORef $! Finalizers 0 M.empty)
(\ioref -> do
Finalizers _ fs <- liftIO (readIORef ioref)
mapM snd (M.toDescList fs) )
(R.runReaderT (unSafeT m))
```

The problem was really about Control.Monad.Catch and last I heard Edward, Gabriel, and Snoyman where going to put their head together and come up with a better Mona.Catch.

I think Gabriel has also mentioned using an idea that is in the ballpark of "free categories" to handle this type of problem among other things.

Here is the example that fails to close the "tmp2" file.

```
ghci> runSafeT . runEffect $ readFile' "tmp" >-> writeFile' "tmp2"
{tmp2 open}
{tmp open}
{tmp closed}
```

I have put the rest of the code in the following gist:
https://gist.github.com/Davorak/f75f6df327cbc4742f16

Contributor guide

No contributing guide indexed for this repository

Research direction

Read the runSafeT definition and the C.bracket finalizer logic shown in the issue, then reproduce the nested-pipe example with runSafeP or runSafeT. Review the linked gist for the complete example and document the conditions under which tmp2 remains open, including the relevant Control.Monad.Catch limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.