fix(uptime): set to 0 instead of returning error on overflow check

This commit is contained in:
yusing
2025-10-09 22:53:38 +08:00
parent 3aed41e078
commit becb49e864

View File

@@ -1,7 +1,6 @@
package routes
import (
"fmt"
"math"
"time"
@@ -37,11 +36,13 @@ func (info *HealthInfo) UnmarshalJSON(data []byte) error {
}
// overflow check
if math.MaxInt64/time.Microsecond < time.Duration(v.Latency) {
return fmt.Errorf("latency overflow: %d", v.Latency)
// Check if latency (in microseconds) would overflow when converted to nanoseconds
if v.Latency > math.MaxInt64/int64(time.Microsecond) {
v.Latency = 0
}
if math.MaxInt64/time.Millisecond < time.Duration(v.Uptime) {
return fmt.Errorf("uptime overflow: %d", v.Uptime)
// Check if uptime (in milliseconds) would overflow when converted to nanoseconds
if v.Uptime > math.MaxInt64/int64(time.Millisecond) {
v.Uptime = 0
}
info.Status = types.NewHealthStatusFromString(v.Status)