bos / pool

A high-performance striped resource pooling implementation for Haskell

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

resource-pool leaks resources

pheaver opened this issue · comments

The resource-pool package does not correctly destroy resources when the pool goes out of scope and is garbage collected. There is a finalizer that terminates the reaper thread, but nothing is done to deal with the outstanding resources.

For example, in the following code, the "destroy" is never printed to the screen:

do
  p <- createPool (putStrLn "create") (\() -> putStrLn "destroy") 1 3 5
  withResource p (\() -> return ())

However, if we add a 4-second delay, which makes sure that p stays in scope long enough for the reaper thread to destroy the resource, then we see "destroy" printed on the screen:

do
  p <- createPool (putStrLn "create") (\() -> putStrLn "destroy") 1 3 5
  withResource p (\() -> return ())
  threadDelay (1000*4000)

Shouldn't be too hard to fix.

This should be fixed by: 73b1473.

I make a release as soon as @bos has added me to the maintainers.