bos / pool

A high-performance striped resource pooling implementation for Haskell
Other
112 stars 59 forks source link

resource-pool leaks resources #12

Closed pheaver closed 10 years ago

pheaver commented 11 years ago

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.

basvandijk commented 10 years ago

This should be fixed by: 73b1473.

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