Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we add timeout for resource acquiring? #10

Open
goosedb opened this issue Aug 16, 2022 · 4 comments · May be fixed by #22
Open

Can we add timeout for resource acquiring? #10

goosedb opened this issue Aug 16, 2022 · 4 comments · May be fixed by #22

Comments

@goosedb
Copy link

goosedb commented Aug 16, 2022

Can we add optional timeout for resource acquiring? Not for creating but taking resource. For now pool waits for available resource infinitely that can be a reason of dead locks.

main :: IO ()
main = do
  pool <- newPool PoolConfig 
    { createResource = pure 0
    , freeResource = const (pure ())
    , poolCacheTTL = 60
    , poolMaxResources = 3
    }

  let takeAnd action = withResource pool (const action)

  putStrLn "-------------\n 1st\n-------------"
  takeAnd do
    print 1
    takeAnd do
      print 2
      takeAnd do 
        print 3
        putStrLn "here!"

  putStrLn "-------------\n 2nd\n-------------"
  takeAnd do
    print 1
    takeAnd do
      print 2
      takeAnd do 
        print 3
        takeAnd do 
          print 4
          putStrLn "here!"

prints

-------------
 1st
-------------
1
2
3
here!
-------------
 2nd
-------------
1
2
3

And gets stuck. Of course, it's a user-code bug. But it's better to get exception than get stuck forever

I'm ready to implement it

@goosedb
Copy link
Author

goosedb commented Aug 17, 2022

anybody @arybczak @soareschen ?

@arybczak
Copy link
Contributor

Sounds good to me. You can add a new configuration option to PoolConfig (a Maybe would work best so that Nothing represents no timeout).

@yitz-zoomin
Copy link

This is important. When our app saturates the pool, requests start backing up, memory use explodes superlinearly, and the app crashes. With a timeout, we could fail gracefully.

@arybczak
Copy link
Contributor

arybczak commented May 19, 2023

There's #11, but it's abandoned. Feel free to pick it up and make it up to date if you need it, so it can be merged 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants