@@ -23,7 +23,8 @@ const unset = -2000
23
23
// CLI runs the agent-exec command. It should only be called by the cli package.
24
24
func CLI () error {
25
25
// 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.
27
28
runtime .LockOSThread ()
28
29
// Nop on success but we do it anyway in case of an error.
29
30
defer runtime .UnlockOSThread ()
@@ -68,12 +69,18 @@ func CLI() error {
68
69
69
70
err = unix .Setpriority (unix .PRIO_PROCESS , 0 , * nice )
70
71
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 )
72
76
}
73
77
74
78
err = writeOOMScoreAdj (* oom )
75
79
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 )
77
84
}
78
85
79
86
path , err := exec .LookPath (args [0 ])
@@ -143,3 +150,7 @@ func execArgs(args []string) []string {
143
150
}
144
151
return nil
145
152
}
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