Skip to content

Async apps flood the screen when DB connection is closed mid-query #90

@akarelas

Description

@akarelas

Run this script:

#!/usr/bin/env perl

use v5.42;
use FindBin '$RealBin';
use lib "$RealBin/../local/lib/perl5";

use Mojo::Base -strict, -async_await;
use Mojo::Pg;

my $pg = Mojo::Pg->new('postgresql://dbuser:dbpass@localhost/dbname');
my $db = $pg->db;

say 'foo1';
await $db->query_p('SELECT PG_SLEEP(60)');
say 'foo2';

And during the 60 seconds between foo1 and foo2, restart postgresql (or find another way to abruptly terminate the connection from the server side).

See a constant flood of this (even after postgresql eventually restarts):

connection not open
connection not open
connection not open
connection not open
connection not open
connection not open
connection not open
connection not open
connection not open
connection not open
connection not open
connection not open
connection not open
connection not open
connection not open

which are really one multi-line error message that repeats itself all the time, and gets bigger and bigger (more lines, while starting from 1-2 lines, so scroll up your terminal to see the original error that ends in "...at $module line $line")

To make your life easier, here's the error message (the first few times):

Mojo::Reactor::Poll: I/O watcher failed: DBD::Pg::db pg_ready failed: FATAL:  terminating connection due to administrator command
SSL connection has been closed unexpectedly
connection not open
connection not open at /home/appuser/work/portal/perl/temp/../local/lib/perl5/Mojo/Pg/Database.pm line 180.
Mojo::Reactor::Poll: I/O watcher failed: DBD::Pg::db pg_ready failed: FATAL:  terminating connection due to administrator command
SSL connection has been closed unexpectedly
connection not open
connection not open
connection not open
connection not open at /home/appuser/work/portal/perl/temp/../local/lib/perl5/Mojo/Pg/Database.pm line 180.
Mojo::Reactor::Poll: I/O watcher failed: DBD::Pg::db pg_ready failed: FATAL:  terminating connection due to administrator command
SSL connection has been closed unexpectedly
connection not open
connection not open
connection not open
connection not open
connection not open
connection not open at /home/appuser/work/portal/perl/temp/../local/lib/perl5/Mojo/Pg/Database.pm line 180.

See how it gets bigger every time.

This affects me a lot, because I want to use pgbouncer which (I want to) terminate the client connection when it tries to start a query when pgbouncer's pool is full, so a solution to this bug would be good for me.

(Having pgbouncer terminate the connection when pgbouncer's pool is full, is the only way I found to prevent my async perl program process from blocking forever (when I don't even want it to block at all) on the $dbh->ping that Mojo::Pg does when dequeuing a $dbh connection from its own pool)

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions