@@ -1669,13 +1669,12 @@ func (a *agent) manageProcessPriority(ctx context.Context, debouncer *logDebounc
1669
1669
}
1670
1670
1671
1671
score , niceErr := proc .Niceness (a .syscaller )
1672
- if niceErr != nil && ! xerrors . Is (niceErr , os . ErrPermission ) {
1672
+ if ! isBenignProcessErr (niceErr ) {
1673
1673
debouncer .Warn (ctx , "unable to get proc niceness" ,
1674
1674
slog .F ("cmd" , proc .Cmd ()),
1675
1675
slog .F ("pid" , proc .PID ),
1676
1676
slog .Error (niceErr ),
1677
1677
)
1678
- continue
1679
1678
}
1680
1679
1681
1680
// We only want processes that don't have a nice value set
@@ -1689,7 +1688,7 @@ func (a *agent) manageProcessPriority(ctx context.Context, debouncer *logDebounc
1689
1688
1690
1689
if niceErr == nil {
1691
1690
err := proc .SetNiceness (a .syscaller , niceness )
1692
- if err != nil && ! xerrors . Is (err , os . ErrPermission ) {
1691
+ if ! isBenignProcessErr (err ) {
1693
1692
debouncer .Warn (ctx , "unable to set proc niceness" ,
1694
1693
slog .F ("cmd" , proc .Cmd ()),
1695
1694
slog .F ("pid" , proc .PID ),
@@ -1703,7 +1702,7 @@ func (a *agent) manageProcessPriority(ctx context.Context, debouncer *logDebounc
1703
1702
if oomScore != unsetOOMScore && oomScore != proc .OOMScoreAdj && ! isCustomOOMScore (agentScore , proc ) {
1704
1703
oomScoreStr := strconv .Itoa (oomScore )
1705
1704
err := afero .WriteFile (a .filesystem , fmt .Sprintf ("/proc/%d/oom_score_adj" , proc .PID ), []byte (oomScoreStr ), 0o644 )
1706
- if err != nil && ! xerrors . Is (err , os . ErrPermission ) {
1705
+ if ! isBenignProcessErr (err ) {
1707
1706
debouncer .Warn (ctx , "unable to set oom_score_adj" ,
1708
1707
slog .F ("cmd" , proc .Cmd ()),
1709
1708
slog .F ("pid" , proc .PID ),
@@ -2139,3 +2138,14 @@ func (l *logDebouncer) log(ctx context.Context, level slog.Level, msg string, fi
2139
2138
}
2140
2139
l .messages [msg ] = time .Now ()
2141
2140
}
2141
+
2142
+ func isBenignProcessErr (err error ) bool {
2143
+ return err != nil &&
2144
+ (xerrors .Is (err , os .ErrNotExist ) ||
2145
+ xerrors .Is (err , os .ErrPermission ) ||
2146
+ isNoSuchProcessErr (err ))
2147
+ }
2148
+
2149
+ func isNoSuchProcessErr (err error ) bool {
2150
+ return err != nil && strings .Contains (err .Error (), "no such process" )
2151
+ }
0 commit comments