From bf9a240a61c3776668fb30d9079f959063daf469 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Tue, 20 Oct 2020 21:38:46 +0000 Subject: [PATCH] [ntp] do not exit if ntp query failed In case of ntp server is busy, we added the following protection. * increase timeout of ntp query * ignore timeout error for ntp query Signed-off-by: Leo Chen --- cmd/harmony/main.go | 10 +++++++--- common/ntp/ntp.go | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index 63ce7fcb3..6ff28d924 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -278,9 +278,13 @@ func setupNodeAndRun(hc harmonyConfig) { // Check NTP configuration accurate, err := ntp.CheckLocalTimeAccurate(nodeConfig.NtpServer) if !accurate { - fmt.Fprintf(os.Stderr, "Error: %v\n", err) - fmt.Fprintf(os.Stderr, "Error: local timeclock is not accurate. Please config NTP properly.\n") - os.Exit(1) + if os.IsTimeout(err) { + fmt.Fprintf(os.Stderr, "Error: %v\n", err) + fmt.Fprintf(os.Stderr, "NTP query timed out. Continuing.\n") + } else { + fmt.Fprintf(os.Stderr, "Error: %v\n", err) + fmt.Fprintf(os.Stderr, "Error: local timeclock is not accurate. Please config NTP properly.\n") + } } if err != nil { utils.Logger().Warn().Err(err).Msg("Check Local Time Accuracy Error") diff --git a/common/ntp/ntp.go b/common/ntp/ntp.go index fddda3934..2173d1917 100644 --- a/common/ntp/ntp.go +++ b/common/ntp/ntp.go @@ -20,7 +20,8 @@ var ( // CheckLocalTimeAccurate returns whether the local clock accurate or not func CheckLocalTimeAccurate(ntpServer string) (bool, error) { - response, err := beevik_ntp.Query(ntpServer) + options := beevik_ntp.QueryOptions{Timeout: 10 * time.Second} + response, err := beevik_ntp.QueryWithOptions(ntpServer, options) // failed to query ntp time if err != nil { return false, err