Skip to content

Commit 9e9e80a

Browse files
authored
fix: revert GetBootTimeNs() to fix timestamp drift (#277)
Revert from commit bcd9064 when `GetBootTimeNs()` was in `internal/consumer/net.go` as `getBootTimeNs()`. Timestamp drift appeared after the first capture: every real second elapsed would be like 2 seconds in the timestamp. For example, with a `ping` command sending ICMP packets every second, the packets would have timestamps that were 2 seconds apart
1 parent af82075 commit 9e9e80a

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

internal/host/host.go

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,12 @@ func GetKernelVersion() (string, error) {
8484
return kernelVersionInfo.version, kernelVersionInfo.err
8585
}
8686

87-
var bootTimeInfo struct {
88-
once sync.Once
89-
ts int64
90-
err error
91-
}
92-
9387
func GetBootTimeNs() (int64, error) {
94-
bootTimeInfo.once.Do(func() {
95-
var ts unix.Timespec
96-
err := unix.ClockGettime(unix.CLOCK_MONOTONIC, &ts)
97-
if err != nil {
98-
bootTimeInfo.err = fmt.Errorf("could not get time: %w", err)
99-
} else {
100-
101-
bootTimeInfo.ts = unix.TimespecToNsec(ts)
102-
}
103-
})
88+
var ts unix.Timespec
89+
err := unix.ClockGettime(unix.CLOCK_MONOTONIC, &ts)
90+
if err != nil {
91+
return 0, fmt.Errorf("could not get time: %w", err)
92+
}
10493

105-
return bootTimeInfo.ts, bootTimeInfo.err
94+
return unix.TimespecToNsec(ts), nil
10695
}

0 commit comments

Comments
 (0)