Skip to content

Commit 5746401

Browse files
committed
make adjusting resource scores non-fatal
1 parent b68a46a commit 5746401

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

agent/agentexec/cli_linux.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ const unset = -2000
2323
// CLI runs the agent-exec command. It should only be called by the cli package.
2424
func CLI() error {
2525
// We lock the OS thread here to avoid a race condition where the nice priority
26-
// we get is on a different thread from the one we set it on.
26+
// we set gets applied to a different thread than the one we exec the provided
27+
// command on.
2728
runtime.LockOSThread()
2829
// Nop on success but we do it anyway in case of an error.
2930
defer runtime.UnlockOSThread()
@@ -68,12 +69,18 @@ func CLI() error {
6869

6970
err = unix.Setpriority(unix.PRIO_PROCESS, 0, *nice)
7071
if err != nil {
71-
return xerrors.Errorf("set nice score: %w", err)
72+
// We alert the user instead of failing the command since it can be difficult to debug
73+
// for a template admin otherwise. It's quite possible (and easy) to set an
74+
// inappriopriate value for niceness.
75+
printfStdErr("failed to adjust niceness to %q: %v", *nice, err)
7276
}
7377

7478
err = writeOOMScoreAdj(*oom)
7579
if err != nil {
76-
return xerrors.Errorf("set oom score: %w", err)
80+
// We alert the user instead of failing the command since it can be difficult to debug
81+
// for a template admin otherwise. It's quite possible (and easy) to set an
82+
// inappriopriate value for oom_score_adj.
83+
printfStdErr("failed to adjust oom score to %q: %v", *nice, err)
7784
}
7885

7986
path, err := exec.LookPath(args[0])
@@ -143,3 +150,7 @@ func execArgs(args []string) []string {
143150
}
144151
return nil
145152
}
153+
154+
func printfStdErr(format string, a ...any) {
155+
_, _ = fmt.Fprintf(os.Stderr, "coder-agent: %s\n", fmt.Sprintf(format, a...))
156+
}

0 commit comments

Comments
 (0)