From 0faddbbfecaa784c584d3a625628c288fe9316c7 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 31 Jul 2020 21:36:18 +0000 Subject: improve error handling on import fork / lock failures v?fork failures seems to be the cause of locks not getting released in -watch. Ensure lock release doesn't get skipped in ->done for both v1 and v2 inboxes. We also need to do everything we can to ensure DB handles, pipes and processes get released even in the face of failure. While we're at it, make failures around `git update-server-info' non-fatal, since smart HTTP seems more popular anyways. v2 changes: - spawn: show failing command - ensure waitpid is synchronous for inotify events - teardown all fast-import processes on exception, not just the failing one - beef up lock_release error handling - release lock on fast-import spawn failure --- lib/PublicInbox/Lock.pm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lib/PublicInbox/Lock.pm') diff --git a/lib/PublicInbox/Lock.pm b/lib/PublicInbox/Lock.pm index ca43682f..b2c8227f 100644 --- a/lib/PublicInbox/Lock.pm +++ b/lib/PublicInbox/Lock.pm @@ -16,20 +16,20 @@ sub lock_acquire { croak 'already locked '.($lock_path // '(undef)') if $self->{lockfh}; return unless defined($lock_path); sysopen(my $lockfh, $lock_path, O_WRONLY|O_CREAT) or - die "failed to open lock $lock_path: $!\n"; - flock($lockfh, LOCK_EX) or die "lock failed: $!\n"; + croak "failed to open $lock_path: $!\n"; + flock($lockfh, LOCK_EX) or croak "lock $lock_path failed: $!\n"; $self->{lockfh} = $lockfh; } sub lock_release { my ($self, $wake) = @_; - return unless $self->{lock_path}; - my $lockfh = delete $self->{lockfh} or croak 'not locked'; + defined(my $lock_path = $self->{lock_path}) or return; + my $lockfh = delete $self->{lockfh} or croak "not locked: $lock_path"; syswrite($lockfh, '.') if $wake; - flock($lockfh, LOCK_UN) or die "unlock failed: $!\n"; - close $lockfh or die "close failed: $!\n"; + flock($lockfh, LOCK_UN) or croak "unlock $lock_path failed: $!\n"; + close $lockfh or croak "close $lock_path failed: $!\n"; } 1; -- cgit v1.2.3-24-ge0c7