Improve recovery scenario on poorly formatted queries.

Because the client defaulted to dying, this left the server in a
strange state as the query question wasn't cleared and the
“fake failure” named pipe was never opened and processed, since it
couldn't be.

The server did eventually recover when the client fully died;
however, the client has enough information to give up its query when
it knows failure has occurred, so that now happens.
This commit is contained in:
Bradley M. Kuhn 2020-06-15 20:40:22 -07:00
parent 6ef1ba0422
commit a21a35d656
No known key found for this signature in database
GPG key ID: F15E8BD6D05E26B3
2 changed files with 9 additions and 5 deletions

View file

@ -30,8 +30,12 @@ sub BeancountQuerySubmit($;$) {
$BEANCOUNT_QUERY{format} = $format if defined $format;
(tied %BEANCOUNT_QUERY)->shunlock;
while (not defined $BEANCOUNT_QUERY{fifoName}) { sleep 1; }
die "Ceci n'est pas une pipe: BEANCOUNT_QUERY{fifoName}, $BEANCOUNT_QUERY{fifoName}:$!"
unless (-p $BEANCOUNT_QUERY{fifoName});
unless (-p $BEANCOUNT_QUERY{fifoName}) {
(tied %BEANCOUNT_QUERY)->shlock;
$BEANCOUNT_QUERY{question} = $BEANCOUNT_QUERY{format} = undef;
(tied %BEANCOUNT_QUERY)->shunlock;
die "Ceci n'est pas une pipe: BEANCOUNT_QUERY{fifoName}, $BEANCOUNT_QUERY{fifoName}:$!"
}
(tied %BEANCOUNT_QUERY)->shlock;
return $BEANCOUNT_QUERY{fifoName};
}

View file

@ -77,7 +77,7 @@ while (1) {
(tied %query)->shlock;
print STDERR "clearing fifo, $query{fifoName}..." if $VERBOSE > 2;
no autodie 'unlink'; unlink($query{fifoName});
$query{fifoName} = undef;
%query = ();
(tied %query)->shunlock;
print STDERR "fifo cleared & lock released." if $VERBOSE > 2;
}
@ -87,9 +87,9 @@ while (1) {
} elsif ($query{question} !~ /^[\-\@\w.\s\"\'\_\(\)]+$/) {
print STDERR "Query string $query{question} looks suspicious, not running beancount query!\n";
(tied %query)->shlock;
$query{question} = $query{format} = undef;
$query{fifoName} = mktemp("REJECTED_beancount-query-fifo-this-file-does-not-exist_${$}_XXXXXXXXX");
(tied %query)->shunlock;
sleep 2;
} elsif (defined $query{format} and $query{format} !~ /^(?:csv|text)$/) {
print STDERR "format string $query{format} is not text or csv, not running beancount query!\n";
(tied %query)->shlock;
@ -100,7 +100,7 @@ while (1) {
my @cmd = ($BEANCOUNT_QUERY_CMD);
push(@cmd, '-f', $query{format}) if defined $query{format};
push(@cmd, $LOAD_FILE, $query{question});
print STDERR "Running query: $query{question}\n" if $VERBOSE > 0;
print STDERR "Runing query: $query{question}\n" if $VERBOSE > 0;
open(my $beancountFH, "-|", @cmd);
print STDERR "Running ", join(" ", @cmd), "\n" if $VERBOSE > 1;
(tied %query)->shlock;