1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-24 09:00:06 +00:00

fix: harden CI test stability and status collector resilience

This commit is contained in:
tw93
2026-03-04 16:09:13 +08:00
parent c88691c2c8
commit ff69504f89
10 changed files with 158 additions and 19 deletions

View File

@@ -2,6 +2,7 @@ package main
import (
"context"
"fmt"
"net/url"
"os"
"runtime"
@@ -13,10 +14,25 @@ import (
"github.com/shirou/gopsutil/v4/net"
)
var ioCountersFunc = net.IOCounters
func collectIOCountersSafely(pernic bool) (stats []net.IOCountersStat, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("panic collecting network counters: %v", r)
}
}()
return ioCountersFunc(pernic)
}
func (c *Collector) collectNetwork(now time.Time) ([]NetworkStatus, error) {
stats, err := net.IOCounters(true)
stats, err := collectIOCountersSafely(true)
if err != nil {
return nil, err
// Some restricted environments can break netstat-backed collectors.
// Degrade gracefully to keep status output available.
c.rxHistoryBuf.Add(0)
c.txHistoryBuf.Add(0)
return nil, nil
}
// Map interface IPs.