paurkedal / ocaml-caqti

Cooperative-threaded access to relational data
https://paurkedal.github.io/ocaml-caqti/index.html
GNU Lesser General Public License v3.0
299 stars 36 forks source link

`connect_pool` doesn't fail with postgresql driver #113

Closed gdiazlo closed 7 months ago

gdiazlo commented 7 months ago

Hello

Writing something like:

  let cfg = Caqti_pool_config.default in
  Caqti_async.connect_pool ~pool_config:cfg (Uri.of_string uri)

behaves differently in pgx and postgresql driver. Particularly, when used with pgx, if the database in uri is not reachable, it will fail with an exception, instead of a result with a Caqti_error

((2024-02-08 23:25:59.892356000+01:00)
 ("unhandled exception"
  ((monitor.ml.Error
    (Unix.Unix_error "Connection refused" connect 127.0.0.1:26257)
    ("Raised at Caqti_driver_pgx.Connect_functor.intercept.(fun) in file \"caqti-driver-pgx/lib/caqti_driver_pgx.ml\", line 261, characters 10-19"
     "Called from Async_kernel__Deferred0.bind.(fun) in file \"src/deferred0.ml\", line 54, characters 64-69"
     "Called from Async_kernel__Job_queue.run_jobs in file \"src/job_queue.ml\", line 180, characters 6-47"
     "Caught by monitor main"))
   ((pid 41834) (thread_id 0)))))

while using the postgresql driver it won't report an error, and the program hangs on pool usage. (this might be related to the async using the pool on other thread? )

I'm using this with caqti-async.

Any hits appreciated!

paurkedal commented 7 months ago

The commit just referred should fix the case you are seeing, though I suspect there are also exceptions from read/write calls which are not intercepted by the current pgx implementation.

paurkedal commented 7 months ago

The latest commits should also cover exceptions from read and write operations if they fail with Core_unix.Unix_error (wrapped in a monitor exception). There'll be a release soon.