PubSub disconnects very often under hypnotoad when EV is installed
akarelas opened this issue · 3 comments
akarelas commented
- Mojo::Pg version: 4.20
- Perl version: 5.32.0
- Operating system: Ubuntu Server 20.04 LXD container within Ubuntu 20.04
- PostgreSQL version: 12.4-1.pgdg20.04+1 (the latest 12 on Ubuntu)
Steps to reproduce the behavior
As UNIX user postgres
, create database my_db
on localhost's postgresql, and allow user dbuser
with password dbuser
to connect to it, eg:
$ createdb my_db
$ createuser -P dbuser # enter `dbuser` as its password when asked
Then download and run this small mojolicious app:
$ git clone git@github.com:akarelas/demo-pubsub-ev-errors.git
$ cd demo-pubsub-ev-errors/
$ carton install
$ carton exec -- hypnotoad ./myapp.pl
Then watch the production log file:
$ tail -f log/production.log
Expected behavior
The log should not repeatedly mention disconnections from the Pg pubsub server.
Actual behavior
The log shows a warning message that Mojolicious disconnected from the pubsub server, many times per minute:
[2020-10-04 14:31:18.69635] [3930] [warn] Re-connected!!!
[2020-10-04 14:31:22.69282] [3929] [warn] Dis-connected!!!
[2020-10-04 14:31:22.69297] [3928] [warn] Dis-connected!!!
[2020-10-04 14:31:22.69329] [3930] [warn] Dis-connected!!!
[2020-10-04 14:31:23.69611] [3929] [warn] Re-connected!!!
[2020-10-04 14:31:23.69616] [3928] [warn] Re-connected!!!
[2020-10-04 14:31:23.69619] [3930] [warn] Re-connected!!!
[2020-10-04 14:31:27.69319] [3930] [warn] Dis-connected!!!
[2020-10-04 14:31:28.69561] [3930] [warn] Re-connected!!!
[2020-10-04 14:31:32.69258] [3929] [warn] Dis-connected!!!
This problem doesn't appear when morbo is running instead of hypnotoad.
akarelas commented
Pasting the current version of myapp.pl
here, in case it gets modified in the future:
#!/usr/bin/env perl
use v5.32;
use warnings;
use FindBin '$RealBin';
use lib "$RealBin/local/lib/perl5";
use Mojolicious::Lite -signatures;
use Mojo::IOLoop;
use Mojo::Pg;
our ($pg, $pubsub);
Mojo::IOLoop->next_tick(sub {
$pg = Mojo::Pg->new('postgresql://dbuser:dbuser@localhost/my_db');
$pubsub = $pg->pubsub;
$pubsub->listen(events => sub {});
$pubsub->on(disconnect => sub {
app->log->warn('Dis-connected!!!');
warn 'Dis-connected';
});
$pubsub->on(reconnect => sub {
app->log->warn('Re-connected!!!');
warn 'Re-connected';
});
Mojo::IOLoop->recurring(5 => sub {
$pubsub->notify(events => 'foo');
});
});
get '/' => sub ($c) {
$c->render(template => 'index');
};
app->start;
__DATA__
@@ index.html.ep
% layout 'default';
% title 'Welcome';
<h1>Welcome to the Mojolicious real-time web framework!</h1>
@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
<head><title><%= title %></title></head>
<body><%= content %></body>
</html>
akarelas commented