Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection string parsing errors incorrectly reported as "PG::UnableToSend: no connection to the server" #302

Closed
edmorley opened this issue Oct 16, 2019 · 5 comments

Comments

@edmorley
Copy link

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

  1. Install Docker and docker-compose

  2. 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
  3. docker-compose run testcase

  4. 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)
@larskanis
Copy link
Collaborator

Thank you for the detailed description of the issue. I'll look at it.

@larskanis
Copy link
Collaborator

I submitted a patch to libpq, that fixes the issue: https://www.postgresql.org/message-id/a9b4cbd7-4ecb-06b2-ebd7-1739bbff3217%40greiz-reinsdorf.de

@edmorley
Copy link
Author

edmorley commented Oct 17, 2019

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)

@larskanis
Copy link
Collaborator

This is fixed in libpq and will be part of PostgreSQL-12.1: postgres/postgres@ba19a6b

@edmorley
Copy link
Author

@larskanis Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants