Don't die when Postgres is down.
authorDavid E. Wheeler <david@justatheory.com>
Mon, 22 Oct 2012 19:03:50 +0000 (12:03 -0700)
committerDavid E. Wheeler <david@justatheory.com>
Mon, 22 Oct 2012 19:03:50 +0000 (12:03 -0700)
commit6a70ebf89eaa6f57fa28d13d92dae99f8255ac55
treeaf61e07d098adb3c1a659f12613cc19891a8bb07
parent54ac34aa5e365b83582345e99f37974a5129f113
Don't die when Postgres is down.

Noticed during tests that sometimes when the `t/20-postgres.t` tests failed,
the `bucardo.mcp.pid` file was left in place. Even though the MCP was gone.
This prevented subsequent tests from running, as they couldn't start the MCP
(Bucardo thought it was still running, because the PID file was still there).

Looking through the log, I noticed that the connection to the database was
dying in `cleanup_mcp()`. Not sure why, but the log said:

    (78512) [Mon Oct 22 12:01:17.638 2012] #0578 MCP Warning: Killed (line 6722): DBD::Pg::db selectcol_arrayref failed: server closed the connection unexpectedly
     This probably means the server terminated abnormally
     before or while processing the request. at /Users/david/dev/postgresql/bucardo/blib/lib/Bucardo.pm line 6722.

That was dying, and the subsequent lines that actually delete the PID file
were therefore never run.

This commit wraps the call to the database in an `eval{}`. If it dies, the
database shutdown time is set to "unknown". We skip further database
interactions when the time is unknown. This allows the shutdown to continue
without exiting, and the MCP PID file gets cleaned up.

Resolves #26.
Bucardo.pm
t/20-postgres.t