As it turns out we can't rely that the script's monitoring session is
terminated with a proper error by the server, because the session
might be terminated while already trying to send data.
Also improve robustness and error reporting facilities of the test,
developed while debugging this issue.
Discussion: https://postgr.es/m/20170920020038.kllxgilo7xzwmtto@alap3.anarazel.de
# kill once with QUIT - we expect psql to exit, while emitting error message first
my$cnt=kill'QUIT',$pid;
@ -105,22 +111,27 @@ my $cnt = kill 'QUIT', $pid;
# Exactly process should have been alive to be killed
is($cnt,1,"exactly one process killed with SIGQUIT");
# Check that psql sees the killed backend as having been terminated
# Check that psql sees the killed backend as having been terminated
$killme_stdin.=q[
SELECT1;
];
$killme->pumpuntil$killme_stderr=~ /WARNING: terminating connection because of crash of another server process/;
ok(1,"psql query died successfully after SIGQUIT");
ok(pump_until($killme,\$killme_stderr,qr/WARNING: terminating connection because of crash of another server process/m),
"psql query died successfully after SIGQUIT");
$killme_stderr='';
$killme_stdout='';
$killme->kill_kill;
# Check if the crash-restart cycle has occurred
$monitor->pumpuntil$monitor_stderr=~ /WARNING: terminating connection because of crash of another server process/;
# Wait till server restarts - we should get the WARNING here, but
# sometimes the server is unable to send that, if interrupted while
# sending.
ok(pump_until($monitor,\$monitor_stderr,qr/WARNING: terminating connection because of crash of another server process|server closed the connection unexpectedly/m),
"psql monitor died successfully after SIGQUIT");
$monitor->kill_kill;
ok(1,"psql monitor died successfully after SIGQUIT");
# Wait till server restarts
is($node->poll_query_until('postgres','SELECT $$restarted$$;','restarted'),"1","reconnected after SIGQUIT");
is($node->poll_query_until('postgres','SELECT $$restarted after sigquit$$;','restarted after sigquit'),
"1","reconnected after SIGQUIT");
# restart psql processes, now that the crash cycle finished
# kill with SIGKILL this time - we expect the backend to exit, without
@ -169,13 +187,15 @@ is($cnt, 1, "exactly one process killed with KILL");
$killme_stdin.=q[
SELECT1;
];
$killme->pumpuntil$killme_stderr=~ /server closed the connection unexpectedly/;
ok(pump_until($killme,\$killme_stderr,qr/server closed the connection unexpectedly/m),
"psql query died successfully after SIGKILL");
$killme->kill_kill;
ok(1,"psql query died successfully after SIGKILL");
# Wait till server restarts (note that we should get the WARNING here)
$monitor->pumpuntil$monitor_stderr=~ /WARNING: terminating connection because of crash of another server process/;
ok(1,"psql monitor died successfully after SIGKILL");
# Wait till server restarts - we should get the WARNING here, but
# sometimes the server is unable to send that, if interrupted while
# sending.
ok(pump_until($monitor,\$monitor_stderr,qr/WARNING: terminating connection because of crash of another server process|server closed the connection unexpectedly/m),
"psql monitor died successfully after SIGKILL");
$monitor->kill_kill;
# Wait till server restarts
@ -198,3 +218,33 @@ is($node->safe_psql('postgres', 'INSERT INTO alive VALUES($$after-orderly-restar
'after-orderly-restart','can still write after orderly restart');