From 90e6da323e07cff71c1c53db7f5432eff241b4a6 Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Mon, 15 Jun 2020 21:29:35 -0700 Subject: [PATCH] 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. --- bean-query-daemon-lib.pl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/bean-query-daemon-lib.pl b/bean-query-daemon-lib.pl index ad4eb1b..089f163 100644 --- a/bean-query-daemon-lib.pl +++ b/bean-query-daemon-lib.pl @@ -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;