Connection string parsing errors incorrectly reported as "PG::UnableToSend: no connection to the server"
Closed this issue · 5 comments
Hi!
libpq
's parsing of integer connection string parameters (such as connect_timeout
) was made more strict in PostgreSQL 12:
postgres/postgres@e7a2217
However these new variants of error messages are not surfaced correctly by ruby-pg
, which instead reports PG::UnableToSend: no connection to the server
, making debugging harder.
STR
-
Install Docker and docker-compose
-
Create the following files:
# docker-compose.yml testcase: build: . links: - db db: image: postgres:11.5-alpine
# Dockerfile FROM ruby:2.6.5-buster RUN curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc -o /etc/apt/trusted.gpg.d/pgdg.asc RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main' > /etc/apt/sources.list.d/pgdg.list RUN apt-get update \ && apt-get install -y --no-install-recommends libpq-dev \ && rm -rf /var/lib/apt/lists/* RUN gem install pg COPY testcase.rb . CMD ["ruby", "testcase.rb"]
# testcase.rb require "pg" connection_parameters = { host: "db", user: "postgres", connect_timeout: "15s", } conn = PG.connect(connection_parameters) conn.exec("SELECT 'test'") do |result| puts "Succeeded" end
-
docker-compose run testcase
-
docker-compose down
Expected
That the docker-compose run testcase
fail with an error message that makes it clear that the connection parameters were incorrect. For example the original libpq error (that doesn't get propagated itself) says:
invalid integer value "15s" for keyword "connect_timeout"
Actual
$ docker-compose run testcase
Starting testcase-pg_db_1 ... done
Traceback (most recent call last):
1: from testcase.rb:11:in `<main>'
testcase.rb:11:in `async_exec': no connection to the server (PG::UnableToSend)
Thank you for the detailed description of the issue. I'll look at it.
I submitted a patch to libpq, that fixes the issue: https://www.postgresql.org/message-id/a9b4cbd7-4ecb-06b2-ebd7-1739bbff3217%40greiz-reinsdorf.de
Oh that's amazing, thank you :-) (The fix being in libpq also means we can pick it up without needing to wait for customers to update their app's pg gem, which really helps)
This is fixed in libpq and will be part of PostgreSQL-12.1: postgres/postgres@ba19a6b
@larskanis Many thanks!