Closed mooreryan closed 6 months ago
Actually I think this may be related: https://github.com/paurkedal/ocaml-caqti/issues/12#issuecomment-380820885 (and the couple of comments surrounding it....
I forgot to mention that returning an error rather than raising will also trigger this:
let _ =
Thread_safe.block_on_async_exn (fun () ->
Caqti_async.with_connection db_connection_uri (fun db ->
let _x = check db in
return (Error (`Msg "oops")) ) )
The missing bind, as you note in the comment, is the problem. The database connection is only valid inside the with_connection
callback. What can happen here is that the check db
call gets scheduled and can then be schedule at a future point. My guess is that it get scheduled while with_connection
is waiting for an internal call to disconnect
to complete.
I'm closing this as it's not a bug, but a limitation of the type-safety provided by the with_connection
(in lack of linear types).
I was playing around with the
with_connection
function trying to break it by doing strange things. For example not binding on the result of executing a query:Gives the monitor error:
rather than the "oh no" exception as I might expect. This also occurs with the caqti-lwt, however not with the blocking version of caqti.
I'm guessing that this is a case of "don't do something like this inside the
with_connection
function...but maybe it is a bug?There are a couple of issues that are potentially related: