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)
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:
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:Shouldn't be too hard to fix.