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