From ff374b8e1c6037478611158b29a90d6fc3d1a145 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Sun, 7 Jun 2026 19:42:35 +0200 Subject: [PATCH] Add a test for https://github.com/ged/ruby-pg/issues/171 This test is added because of #721. It is in preparation of no longer unlocking the GVL in QPsend* functions. --- spec/pg/connection_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spec/pg/connection_spec.rb b/spec/pg/connection_spec.rb index c17d2654f..1546344f7 100644 --- a/spec/pg/connection_spec.rb +++ b/spec/pg/connection_spec.rb @@ -430,6 +430,25 @@ end end + it "can emit messages in PQsend*, https://github.com/ged/ruby-pg/issues/171", :without_transaction do + port_ro = @port + 2 + @dbms = PG::TestingHelpers::PostgresServer.new("stopping", port: port_ro) + pg = PG.connect( host: @dbms.unix_socket, port: port_ro, dbname: "postgres" ) + pg.set_notice_processor {} + pg.prepare('time_now', 'SELECT current_timestamp') + + # Server close emits a message: + # "FATAL: terminating connection due to administrator command\n" + @dbms.teardown + + # libpq version <= 11 emits messages while PQsend* functions. + # This crashed on ruby <= 3.3 due to locking GVL which is already locked. + pg.send_query_prepared('time_now') + pg.get_result + rescue PG::UnableToSend, PG::ConnectionBad + # OK, didn't crash + end + context "with multiple PostgreSQL servers", :without_transaction do before :all do @port_ro = @port + 1