Add timeout to client when server never creates FIFO.

If the server never creates the named pipe, then this loop originally
hung forever.  The count it now waits for is arbitrary, and probably
could be smaller, since the current implementation of the server
creates the pipe within 3-6 seconds under normal conditions.
This commit is contained in:
Bradley M. Kuhn 2020-06-15 21:29:35 -07:00
parent 975cceeaab
commit 90e6da323e
No known key found for this signature in database
GPG key ID: F15E8BD6D05E26B3

View file

@ -29,7 +29,16 @@ sub BeancountQuerySubmit($;$) {
$BEANCOUNT_QUERY{question} = $question;
$BEANCOUNT_QUERY{format} = $format if defined $format;
(tied %BEANCOUNT_QUERY)->shunlock;
while (not defined $BEANCOUNT_QUERY{fifoName}) { sleep 1; }
my $cnt = 0;
while (not defined $BEANCOUNT_QUERY{fifoName}) {
sleep 1;
if ($cnt++ >= (5 * 60)) {
(tied %BEANCOUNT_QUERY)->shlock;
$BEANCOUNT_QUERY{question} = $BEANCOUNT_QUERY{format} = undef;
(tied %BEANCOUNT_QUERY)->shunlock;
die "Unable to initiate query to beancount server\n";
}
}
unless (-p $BEANCOUNT_QUERY{fifoName}) {
(tied %BEANCOUNT_QUERY)->shlock;
$BEANCOUNT_QUERY{question} = $BEANCOUNT_QUERY{format} = undef;