mojolicious / mojo-pg

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

Infinity loop with pg_notifies error #9

Closed Logioniz closed 9 years ago

Logioniz commented 9 years ago

After running test have error in console if use pubsub

#!/usr/bin/perl -w
use Mojolicious::Lite;

use Mojo::Pg;
use Test::Mojo;
use Test::More;

helper pg => sub { state $pg = Mojo::Pg->new('postgresql://logioniz@/test?PrintError=1&RaiseError=0') };

plugin 'ForkCall';

websocket '/ws' => sub {
  my $c = shift;
  my $cb = $c->pg->pubsub->listen(notification => sub { });
  $c->on(finish => sub { shift->pg->pubsub->unlisten(notification => $cb) });
} => 'ws';

get '/file' => sub {
  my $c = shift->render_later;
  $c->fork_call(sub { return 'some result' }, [], sub { $c->render(text => 'qwe')});
} => 'file';

app->start;

my $t = Test::Mojo->new();

$t->websocket_ok('/ws');
$t->get_ok('/file');

done_testing;
$ prove 2.pl 
2.pl .. 1/? DBD::Pg::db pg_notifies failed: server closed the connection unexpectedly
    This probably means the server terminated abnormally
    before or while processing the request. at /usr/local/share/perl/5.20.2/Mojo/Pg/Database.pm line 110, <DATA> line 2231.
DBD::Pg::db pg_notifies failed: connection not open at /usr/local/share/perl/5.20.2/Mojo/Pg/Database.pm line 110, <DATA> line 2231.
.....
DBD::Pg::db pg_notifies failed: connection not open at /usr/local/share/perl/5.20.2/Mojo/Pg/Database.pm line 110, <DATA> line 2231.
2.pl .. ok   
All tests successful.
Files=1, Tests=2,  1 wallclock secs ( 0.03 usr  0.00 sys +  0.25 cusr  0.01 csys =  0.29 CPU)
Result: PASS
$ perl -MMojo::Pg -le 'print $Mojo::Pg::VERSION'
2.07
$ perl -MMojolicious -le 'print $Mojolicious::VERSION'
6.13
kraih commented 9 years ago

Doesn't look like a bug to me, but patches would be welcome if you have an idea for how to handle this better.

kraih commented 9 years ago

And for the record, RaiseError=1 is currently required. http://mojolicio.us/perldoc/Mojo/Pg#options

vividsnow commented 4 years ago

this is still an issue when connection to pg server is closed unexpectedly, logs flooded with:

Mojo::Reactor::EV: I/O watcher failed: DBD::Pg::db pg_notifies failed: connection not open at ../lib/perl5/Mojo/Pg/Database.pm line 141
kraih commented 4 years ago

I'm sorry but we will not support RaiseError=0.

vividsnow commented 4 years ago

I got same infinite loop with default options and pg_server_prepare=0

kraih commented 4 years ago

Then you did not have the same problem.

vividsnow commented 4 years ago

Yes, but it's closely related. Should I open separate issue?

kobaz commented 10 months ago

This problem still exists.

Options

{ 'AutoInactiveDestroy' => 1, 'AutoCommit' => 1, 'RaiseError' => 1, 'PrintWarn' => 0, 'PrintError' => 0 };

Mojo::Reactor::Poll: I/O watcher failed: DBD::Pg::db pg_notifies failed: connection not open at /usr/local/library/perl/lib/perl5/Mojo/Pg/Database.pm line 140.

Endless loop using 100% cpu

viyer2 commented 10 months ago

@kobaz
Are you using the latest version of the Mojo::Pg module ?

The subroutine containing the error line in question should like this. If not please upgrade to the latest version(4.27).

sub _notifications { my $self = shift;

my $dbh = $self->dbh; my $n; return undef unless $n = eval { $dbh->pg_notifies }; while ($n) { $self->emit(notification => @$n); $n = eval { $dbh->pg_notifies }; }

return 1; }

kobaz commented 8 months ago

This was 4.19. We will retry with 4.27.

Thanks.