1. Michael Granger
  2. ruby-pg


Issue #165 resolved

PGconn.connect_start blocks the whole ruby process

Masashi Miyazaki
created an issue

When trying to connect to the some specific unresolved hostname(ex: foobar.us-east-1.redshift.amazonaws.com), PG::Connection.connect_start blocks the whole ruby process until timeout.

I'm using 'pg' gem to connect to an Amazon Redshift Cluster, and it happens when trying to connect to a terminated cluster.

You can reproduce it with the attachment file. The result is as following.

$ ruby test_ruby_db_drivers_block_in_connect2.rb pg
....................[pg: connecting to unreachable database (foobar.us-east-1.amazonaws.com)]
test_ruby_db_drivers_block_in_connect3.rb:31:in `connect_start': could not translate host name "foobar.us-east-1.redshift.amazonaws.com" to address: nodename nor servname provided, or not known (PG::Error)
     from test_ruby_db_drivers_block_in_connect3.rb:31:in `<main>'

Comments (6)

  1. Lars Kanis

    Thanks for reporting this! The PostgreSQL documentation has some notes about the conditions for non blocking behavior: http://www.postgresql.org/docs/9.2/static/libpq-connect.html#LIBPQ-PQCONNECTSTARTPARAMS This makes sure that connect_start returns immediately and so will also not block other ruby threads. In your case libpq must do a DNS query and will block therefore.

    Nevertheless, the connection functions in ruby-pg should not not block other ruby threads in any case. So I'll change them to release the GVL accordingly.

  2. Log in to comment