Skip to content

Commit ce73e60

Browse files
committed
Revert "refactor: ntp init logs but not panic (#1568)"
This reverts commit 00256fd.
1 parent 91da615 commit ce73e60

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

core/ntp.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,24 @@ import (
1414
type NTPSyncedClock struct {
1515
offset int64
1616
logger logging.Logger
17+
cancel context.CancelFunc
1718
}
1819

1920
// NewNTPSyncedClock creates a new NTP synchronized clock and starts background sync.
20-
func NewNTPSyncedClock(ctx context.Context, server string, syncInterval time.Duration, logger logging.Logger) (*NTPSyncedClock, error) {
21+
func NewNTPSyncedClock(parentCtx context.Context, server string, syncInterval time.Duration, logger logging.Logger) (*NTPSyncedClock, error) {
2122
if logger == nil {
2223
return nil, fmt.Errorf("logger must not be nil")
2324
}
25+
ctx, cancel := context.WithCancel(parentCtx)
2426

2527
clock := &NTPSyncedClock{
2628
logger: logger.With("component", "NTPSyncedClock"),
29+
cancel: cancel,
2730
}
2831

29-
// Try to sync once, but don't fail if it doesn't work
3032
if err := clock.syncOnce(server); err != nil {
31-
clock.logger.Warn("Initial NTP sync failed, will retry in background and use system clock until sync succeeds", "err", err)
33+
cancel()
34+
return nil, fmt.Errorf("initial NTP query failed: %w", err)
3235
}
3336

3437
go clock.runSyncLoop(ctx, server, syncInterval)
@@ -64,7 +67,6 @@ func (c *NTPSyncedClock) syncOnce(server string) error {
6467
}
6568

6669
// Now returns the current time compensated by the latest NTP offset.
67-
// If the NTP sync has not yet succeeded, it returns the current system time.
6870
func (c *NTPSyncedClock) Now() time.Time {
6971
offset := atomic.LoadInt64(&c.offset)
7072
return time.Now().Add(time.Duration(offset))

0 commit comments

Comments
 (0)