From 398f12660f8e2f2251c76ce991ecf76ec21abed4 Mon Sep 17 00:00:00 2001 From: Greg Sabino Mullane Date: Fri, 16 Mar 2012 13:41:09 -0400 Subject: [PATCH] Sleep a bit after we fork the VAC daemon, to decrease the chances of things blowing up if the MCP dies before we call inactivedestroy on the forked handles. --- Bucardo.pm | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Bucardo.pm b/Bucardo.pm index 0f47b118d..0ed3b0511 100644 --- a/Bucardo.pm +++ b/Bucardo.pm @@ -6184,6 +6184,10 @@ sub fork_vac { if ($newpid) { ## We are the parent $self->glog(qq{Created VAC $newpid}, LOG_NORMAL); $self->{vacpid} = $newpid; + ## We sleep a bit here to increase the chance that the database connections + ## below are disassociated before the MCP can come back and possibly + ## kill the VAC, causing bad double-free libpq/libc errors + sleep 0.5; return; } @@ -6193,6 +6197,7 @@ sub fork_vac { $self->{masterdbh}->{InactiveDestroy} = 1; $self->{masterdbh} = 0; + ## We also need to disassociate ourselves from any open database connections for my $dbname (keys %{ $self->{sdb} }) { $x = $self->{sdb}{$dbname}; next if $x->{dbtype} =~ /flat|mongo|redis/o; @@ -6220,9 +6225,6 @@ sub fork_vac { die "MCP request\n"; }; - ## From this point forward, we want to die gracefully - #$SIG{TERM} = 'IGNORE'; - ## From this point forward, we want to die gracefully $SIG{__DIE__} = sub { @@ -6240,8 +6242,7 @@ sub fork_vac { $self->glog(qq{${warn}VAC was killed at line $line: $diemsg}, LOG_WARN); ## Not a whole lot of cleanup to do on this one: just shut database connections and leave - - ## TODO: Disconnect from all databases + $self->{masterdbh}->disconnect(); ## Remove our pid file unlink $self->{vacpidfile} or $self->glog("Warning! Failed to unlink $self->{vacpidfile}", LOG_WARN); -- 2.39.5