Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3716afa

Browse files
authored
fix: add benign error suppression for process priority management (#15020)
This PR backports some benign error suppression into 2.15
1 parent0f63510 commit3716afa

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

‎agent/agent.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,13 +1669,12 @@ func (a *agent) manageProcessPriority(ctx context.Context, debouncer *logDebounc
16691669
}
16701670

16711671
score,niceErr:=proc.Niceness(a.syscaller)
1672-
ifniceErr!=nil&&!xerrors.Is(niceErr,os.ErrPermission) {
1672+
if!isBenignProcessErr(niceErr) {
16731673
debouncer.Warn(ctx,"unable to get proc niceness",
16741674
slog.F("cmd",proc.Cmd()),
16751675
slog.F("pid",proc.PID),
16761676
slog.Error(niceErr),
16771677
)
1678-
continue
16791678
}
16801679

16811680
// 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
16891688

16901689
ifniceErr==nil {
16911690
err:=proc.SetNiceness(a.syscaller,niceness)
1692-
iferr!=nil&&!xerrors.Is(err,os.ErrPermission) {
1691+
if!isBenignProcessErr(err) {
16931692
debouncer.Warn(ctx,"unable to set proc niceness",
16941693
slog.F("cmd",proc.Cmd()),
16951694
slog.F("pid",proc.PID),
@@ -1703,7 +1702,7 @@ func (a *agent) manageProcessPriority(ctx context.Context, debouncer *logDebounc
17031702
ifoomScore!=unsetOOMScore&&oomScore!=proc.OOMScoreAdj&&!isCustomOOMScore(agentScore,proc) {
17041703
oomScoreStr:=strconv.Itoa(oomScore)
17051704
err:=afero.WriteFile(a.filesystem,fmt.Sprintf("/proc/%d/oom_score_adj",proc.PID), []byte(oomScoreStr),0o644)
1706-
iferr!=nil&&!xerrors.Is(err,os.ErrPermission) {
1705+
if!isBenignProcessErr(err) {
17071706
debouncer.Warn(ctx,"unable to set oom_score_adj",
17081707
slog.F("cmd",proc.Cmd()),
17091708
slog.F("pid",proc.PID),
@@ -2139,3 +2138,14 @@ func (l *logDebouncer) log(ctx context.Context, level slog.Level, msg string, fi
21392138
}
21402139
l.messages[msg]=time.Now()
21412140
}
2141+
2142+
funcisBenignProcessErr(errerror)bool {
2143+
returnerr!=nil&&
2144+
(xerrors.Is(err,os.ErrNotExist)||
2145+
xerrors.Is(err,os.ErrPermission)||
2146+
isNoSuchProcessErr(err))
2147+
}
2148+
2149+
funcisNoSuchProcessErr(errerror)bool {
2150+
returnerr!=nil&&strings.Contains(err.Error(),"no such process")
2151+
}

‎agent/agentproc/proc_unix.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,15 @@ func List(fs afero.Fs, syscaller Syscaller) ([]*Process, error) {
4545

4646
cmdline,err:=afero.ReadFile(fs,filepath.Join(defaultProcDir,entry,"cmdline"))
4747
iferr!=nil {
48-
varerrNo syscall.Errno
49-
ifxerrors.As(err,&errNo)&&errNo==syscall.EPERM {
48+
ifisBenignError(err) {
5049
continue
5150
}
5251
returnnil,xerrors.Errorf("read cmdline: %w",err)
5352
}
5453

5554
oomScore,err:=afero.ReadFile(fs,filepath.Join(defaultProcDir,entry,"oom_score_adj"))
5655
iferr!=nil {
57-
ifxerrors.Is(err,os.ErrPermission) {
56+
ifisBenignError(err) {
5857
continue
5958
}
6059

@@ -124,3 +123,12 @@ func (p *Process) Cmd() string {
124123
func (p*Process)cmdLine() []string {
125124
returnstrings.Split(p.CmdLine,"\x00")
126125
}
126+
127+
funcisBenignError(errerror)bool {
128+
varerrno syscall.Errno
129+
if!xerrors.As(err,&errno) {
130+
returnfalse
131+
}
132+
133+
returnerrno==syscall.ESRCH||errno==syscall.EPERM||xerrors.Is(err,os.ErrNotExist)
134+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp