mojolicious / mojo-pg

Mojolicious :heart: PostgreSQL
https://metacpan.org/release/Mojo-Pg
Artistic License 2.0
101 stars 46 forks source link

Certain sequence of async queries in nested async subs pauses indefinitely #84

Closed akarelas closed 2 years ago

akarelas commented 2 years ago

Steps to reproduce the behavior

This script pauses after passing after query 1, and never passes after query 2.

use Mojo::Base -strict, -async_await;

use Test::More;

use Mojo::Pg;
use Mojo::IOLoop;

plan $ENV{TEST_ONLINE} ? (tests => 3)
    : (skip_all => 'set TEST_ONLINE to enable this test');

my $pg = Mojo::Pg->new($ENV{TEST_ONLINE});
my $db = $pg->db;

my $sub = async sub {
    (await $db->query_p("SELECT 10"))->array;
};

(async sub {
    pass 'before query 1';
    await $sub->();
    pass 'after query 1';
    await $sub->();
    pass 'after query 2';
})->();

Mojo::IOLoop->start;

Expected behavior

All three tests should pass and the test should complete.

Actual behavior

The first two tests pass, and then program pauses execution.

user@server:~/temp$ TEST_ONLINE=postgresql://user:pass@localhost/dbname prove -vl -Ilocal/lib/perl5 test.t
test.t .. 
1..3
ok 1 - before query 1
ok 2 - after query 1

...followed by a pause.

akarelas commented 2 years ago

Temporary workaround until this bug gets fixed: replaced all ->hash in my programs with ->hashes->[0] and all ->array with ->arrays->[0].

akarelas commented 2 years ago

I saw that Mojo-Pg is not the cause of this behavior. I'm closing this issue.

akarelas commented 2 years ago

Related: https://gist.github.com/akarelas/93df86b8c05428e20fac43a9bedd6e19