Merge pull request #3397 from LeoHChen/ntp

[ntp] do not exit if ntp query failed
pull/3400/head
Rongjian Lan 4 years ago committed by GitHub
commit 198e33e637
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      cmd/harmony/main.go
  2. 3
      common/ntp/ntp.go

@ -278,9 +278,13 @@ func setupNodeAndRun(hc harmonyConfig) {
// Check NTP configuration // Check NTP configuration
accurate, err := ntp.CheckLocalTimeAccurate(nodeConfig.NtpServer) accurate, err := ntp.CheckLocalTimeAccurate(nodeConfig.NtpServer)
if !accurate { if !accurate {
fmt.Fprintf(os.Stderr, "Error: %v\n", err) if os.IsTimeout(err) {
fmt.Fprintf(os.Stderr, "Error: local timeclock is not accurate. Please config NTP properly.\n") fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1) 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 { if err != nil {
utils.Logger().Warn().Err(err).Msg("Check Local Time Accuracy Error") utils.Logger().Warn().Err(err).Msg("Check Local Time Accuracy Error")

@ -20,7 +20,8 @@ var (
// CheckLocalTimeAccurate returns whether the local clock accurate or not // CheckLocalTimeAccurate returns whether the local clock accurate or not
func CheckLocalTimeAccurate(ntpServer string) (bool, error) { 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 // failed to query ntp time
if err != nil { if err != nil {
return false, err return false, err

Loading…
Cancel
Save