arenadotio / pgx

A pure OCaml PostgreSQL client library
Other
122 stars 16 forks source link

Server hangs up during authentication #121

Closed paurkedal closed 2 years ago

paurkedal commented 2 years ago

When running the test suite of the current master (3f2c0fc385db40d108466df80dad7980587d4342) against a INET socket, each DB test hangs until the server disconnects with FATAL: canceling authentication due to timeout. This does not happen for UNIX domain socket. My test procedure is to start up a postgresql server like

docker run --rm -it -e POSTGRES_PASSWORD=Bw8D7YHufq11gcS4 -p 127.0.0.1:15432:5432 postgres

and run the test suite like

PGPORT=15432 PGHOST=localhost PGUSER=postgres PGDATABASE=postgres PGPASSWORD=Bw8D7YHufq11gcS4 dune runtest

The async tests report something like

ASSERT test db connection timed out after 2s
[exception] (monitor.ml.Error
  ( "Alcotest assertion failure\
   \n\027[31mFAIL\027[0m test db connection timed out after 2s\
   \n")
  ("Raised at file \"src/alcotest-engine/test.ml\", line 157, characters 20-48"
    "Called from file \"src/deferred1.ml\", line 17, characters 40-45"
    "Called from file \"src/job_queue.ml\", line 167, characters 6-47"))
            Raised at file "src/alcotest-engine/test.ml", line 157, characters 20-48
            Called from file "src/deferred1.ml", line 17, characters 40-45
            Called from file "src/job_queue.ml", line 167, characters 6-47

and the lwt tests report

[exception] End_of_file
            Raised by primitive operation at file "src/unix/lwt_unix.cppo.ml", line 690, characters 8-59
            Called from file "src/unix/lwt_unix.cppo.ml", line 571, characters 17-28
gtrak commented 2 years ago

What version of postgres is it? I noticed a timeout issue with the version 14 docker image recently, but 13 works.

gtrak commented 2 years ago

I think what's happening is we don't yet support SASL and SCRAM-SHA-256. I've debugged the handshake between 13 and 14. I think it's more involved to support it, but in the meantime I can add an error instead of the timeout. If you are in control of the server config, MD5 should still be an option for newer postgres's. image image

paurkedal commented 2 years ago

Yes, it's version 14.1. An informative error would be good.

gtrak commented 2 years ago

Testing #122 and will get it out today.

paurkedal commented 2 years ago

Looks good, I'm getting an immediate Pgx: SASL Credential authentication not supported with the PR pinned. Thanks!