From 393e2c4e802677561a6bc1e61b522ba4ad8b5c70 Mon Sep 17 00:00:00 2001 From: Alex Grintsvayg Date: Thu, 8 Mar 2018 19:27:54 -0500 Subject: [PATCH] add daemon timeout option, stop ytsync gracefully during daemon startup --- ytsync.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ytsync.go b/ytsync.go index 635db20..d9f4d28 100644 --- a/ytsync.go +++ b/ytsync.go @@ -134,7 +134,22 @@ func (s *Sync) FullCycle() error { } log.Infoln("Waiting for daemon to finish starting...") - s.daemon = jsonrpc.NewClientAndWait("") + s.daemon = jsonrpc.NewClient("") + s.daemon.SetRPCTimeout(5 * time.Minute) + +WaitForDaemonStart: + for { + select { + case <-s.stop.Chan(): + return nil + default: + _, err := s.daemon.WalletBalance() + if err == nil { + break WaitForDaemonStart + } + time.Sleep(5 * time.Second) + } + } err = s.doSync() if err != nil {