bos / pool

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

How to make "createPool" fail fast when given a bad connection string? #33

Open runeksvendsen opened 5 years ago

runeksvendsen commented 5 years ago

Hi there,

Thanks for creating this library!

I have a question about how to make the following servant example using resource-pool fail immediately when given an invalid connection string: https://haskell-servant.readthedocs.io/en/stable/cookbook/db-postgres-pool/PostgresPool.html

If the main function of the example is modified to only start the server:

main :: IO ()
main = do
  -- you could read this from some configuration file,
  -- environment variable or somewhere else instead.
  -- you will need to either change this connection string OR
  -- set some environment variables (see
  -- https://www.postgresql.org/docs/9.5/static/libpq-envars.html)
  -- to point to a running PostgreSQL server for this example to work.
  let connStr = ""
  pool <- initConnectionPool connStr
  runApp pool

the server will happily start without errors, but throw an exception each time a request is handled (because connStr is invalid).

Shouldn't createPool create a resource pool immediately -- and thus fail at this point -- rather than wait until withResource is called?