mojolicious / mojo-pg

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

Error while global destruction #4

Closed avkhozov closed 9 years ago

avkhozov commented 9 years ago

I sometimes get an error (in cleanup) Can't call method "FETCH" on an undefined value at /home/and/perl5/perlbrew/perls/perl 5.20.0/lib/site_perl/5.20.0/Mojo/Pg.pm line 91, <DATA> line 440 during global destruction. while using Minion (1.13) and Mojo::Pg (2.01)

avkhozov commented 9 years ago

Maybe it happens when I use notify from worker via $job->app->pg->pubsub->notify, but for now I can't create a minimal example.

kraih commented 9 years ago

I've never seen this, so i'm afraid without a test case there is nothing we can do.

Logioniz commented 9 years ago

I have this error/warning too (If it would change anything).

kraih commented 9 years ago

@Logioniz Only if you can provide a test case.

avkhozov commented 9 years ago

Application:

#!/usr/bin/env perl
use Mojolicious::Lite;

use Minion;
use Mojo::Pg;

my $pg_uri = 'postgresql://test@/test';
app->plugin(Minion => {Pg => $pg_uri});
helper pg => sub { state $pg = Mojo::Pg->new($pg_uri) };

app->pg->pubsub->listen(test => sub { say app->minion->job($_[1])->info->{result} });
app->minion->add_task(test => sub {
  system('/bin/sleep 1');
  say 'test';
  $_[0]->finish(rand);
  $_[0]->app->pg->pubsub->notify(test => $_[0]->id)
});

app->start;

Enqueue tasks:

$ for i in {1..100}; do perl t.pl minion job -e test; done

Run worker and send SIGINT to process:

$ perl t.pl minion worker
test
0.0406342305160585
test
^Ctest
test
^Ctest
test
test
test
0.0460506010770949
^C^Ctest
test
^C^C^C^C^Ctest
test
test
    (in cleanup) Can't call method "FETCH" on an undefined value at /home/and/perl5/perlbrew/perls/perl-5.20.0/lib/site_perl/5.20.0/Mojo/Pg.pm line 91, <DATA> line 440 during global destruction.
0.173964488776143
    (in cleanup) Can't call method "FETCH" on an undefined value at /home/and/perl5/perlbrew/perls/perl-5.20.0/lib/site_perl/5.20.0/Mojo/Pg.pm line 91, <DATA> line 440 during global destruction.
    (in cleanup) Can't call method "FETCH" on an undefined value at /home/and/perl5/perlbrew/perls/perl-5.20.0/lib/site_perl/5.20.0/Mojo/Pg.pm line 91, <DATA> line 440 during global destruction.
test
    (in cleanup) Can't call method "FETCH" on an undefined value at /home/and/perl5/perlbrew/perls/perl-5.20.0/lib/site_perl/5.20.0/Mojo/Pg.pm line 91, <DATA> line 440 during global destruction.
test
test
test
    (in cleanup) Can't call method "FETCH" on an undefined value at /home/and/perl5/perlbrew/perls/perl-5.20.0/lib/site_perl/5.20.0/Mojo/Pg.pm line 91, <DATA> line 440 during global destruction.
    (in cleanup) Can't call method "FETCH" on an undefined value at /home/and/perl5/perlbrew/perls/perl-5.20.0/lib/site_perl/5.20.0/Mojo/Pg.pm line 91, <DATA> line 440 during global destruction.
    (in cleanup) Can't call method "FETCH" on an undefined value at /home/and/perl5/perlbrew/perls/perl-5.20.0/lib/site_perl/5.20.0/Mojo/Pg.pm line 91, <DATA> line 440 during global destruction.
test

Get errors in random order.

kraih commented 9 years ago

@avkhozov Afraid i was still not able to replicate the problem.

kraih commented 9 years ago

I suspect this will make the problem go away, but i'm not sure if it is the correct solution. https://github.com/kraih/mojo-pg/commit/a8dbeab671ec2e4c980637beb3d7627fc74f74f6

avkhozov commented 9 years ago

Ok, I'm going to test further.

kraih commented 9 years ago

This one is related too, database handles should never be reused after forking. https://github.com/kraih/mojo-pg/commit/0d2333d3ef29c60e67ddaa77f73fa203b49d7de5

Epiphero commented 8 years ago

@kraih a8dbeab did indeed fix a similar problem for me.