From 140b2deec04f9240a7d710fe764f47216d67484c Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 9 Oct 2021 14:38:51 +1030 Subject: [PATCH] channeld: fix halting gossip when a timer is active. We would sleep until the next timer, even if that's long past when we would send gossip. Normally we use very short timers, so we didn't notice, but we will in the next patch, where we use continuous timers for pings. Signed-off-by: Rusty Russell --- channeld/channeld.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/channeld/channeld.c b/channeld/channeld.c index aa90df5ca..368c84776 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -3923,15 +3923,21 @@ int main(int argc, char *argv[]) continue; } + /* Might not be waiting for anything. */ + tptr = NULL; + if (timer_earliest(&peer->timers, &first)) { timeout = timespec_to_timeval( timemono_between(first, now).ts); tptr = &timeout; - } else if (time_to_next_gossip(peer->pps, &trel)) { + } + + /* If timer to next gossip is sooner, use that instead. */ + if (time_to_next_gossip(peer->pps, &trel) + && (!tptr || time_less(trel, timeval_to_timerel(*tptr)))) { timeout = timerel_to_timeval(trel); tptr = &timeout; - } else - tptr = NULL; + } if (select(nfds, &rfds, NULL, NULL, tptr) < 0) { /* Signals OK, eg. SIGUSR1 */