Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pkg/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,12 @@ func (m *Manager) AssignPID(key string, pid int) error {
if err != nil {
return fmt.Errorf("failed to open tasks file for key %s: %w", key, err)
}
defer f.Close()

data := []byte(strconv.Itoa(pid) + "\n")
if _, err := f.Write(data); err != nil {
f.Close() //nolint:errcheck // report the write error
return fmt.Errorf("failed to write pid %d for key %s: %w", pid, key, err)
}
if err := f.Close(); err != nil {
return fmt.Errorf("failed to write pid %d for key %s: %w", pid, key, err)
}
log().Info("assigned PID to mon_group", "key", key, "pid", pid)
Expand Down Expand Up @@ -411,7 +413,7 @@ func pidInTasksFile(path string, pid int) (bool, error) {
}
return false, fmt.Errorf("failed to open tasks file %s: %w", path, err)
}
defer f.Close()
defer f.Close() //nolint:errcheck // read-only

target := strconv.Itoa(pid)
sc := bufio.NewScanner(f)
Expand Down
8 changes: 5 additions & 3 deletions pkg/monitor/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,8 @@ func TestRemove_ConcurrentEnsureGroup(t *testing.T) {

var wg sync.WaitGroup
wg.Go(func() {
mgr.Remove("pod-uid-1")
// Racing with EnsureGroup, we're not interested in the error but the state (checked later)
_ = mgr.Remove("pod-uid-1")
})
var ensureErr error
wg.Go(func() {
Expand Down Expand Up @@ -969,10 +970,11 @@ func TestRemove_ConcurrentReadCounters(t *testing.T) {
go func() {
defer close(done)
for i := 0; i < 100; i++ {
mgr.ReadCounters("pod-uid-1")
// Racing with Remove below so errors are expected, we only assert on no panic/data race
_, _ = mgr.ReadCounters("pod-uid-1")
}
}()
// Give the reader goroutine a head start, then remove.
mgr.Remove("pod-uid-1")
_ = mgr.Remove("pod-uid-1")
<-done
}
2 changes: 1 addition & 1 deletion pkg/monitor/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func isHex(s string) bool {
return false
}
for _, c := range s {
if !((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) {
if (c < '0' || c > '9') && (c < 'a' || c > 'f') && (c < 'A' || c > 'F') {
return false
}
}
Expand Down