Skip to content

fix: fix oom_score adjustments failing if caps set #15758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Dec 5, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
lock thread at the top
  • Loading branch information
sreya committed Dec 4, 2024
commit 158e11722b7dfebb95744ee83aa1df1ac750b7b6
16 changes: 7 additions & 9 deletions agent/agentexec/cli_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ import (

// CLI runs the agent-exec command. It should only be called by the cli package.
func CLI() error {
// We lock the OS thread here to avoid a race condition where the nice priority
// we set gets applied to a different thread than the one we exec the provided
// command on.
runtime.LockOSThread()
// Nop on success but we do it anyway in case of an error.
defer runtime.UnlockOSThread()

var (
fs = flag.NewFlagSet("agent-exec", flag.ExitOnError)
nice = fs.Int("coder-nice", unset, "")
Expand All @@ -36,7 +43,6 @@ func CLI() error {
return xerrors.Errorf("parse flags: %w", err)
}

fmt.Println("oom", *oom)
if *oom == unset {
// If an explicit oom score isn't set, we use the default.
*oom, err = defaultOOMScore()
Expand All @@ -49,7 +55,6 @@ func CLI() error {
if err != nil {
printfStdErr("failed to set dumpable: %v", err)
}
fmt.Println("set dumpable")

err = writeOOMScoreAdj(*oom)
if err != nil {
Expand All @@ -59,13 +64,6 @@ func CLI() error {
printfStdErr("failed to adjust oom score to %d for cmd %+v: %v", *oom, execArgs(os.Args), err)
}

// We lock the OS thread here to avoid a race condition where the nice priority
// we set gets applied to a different thread than the one we exec the provided
// command on.
runtime.LockOSThread()
// Nop on success but we do it anyway in case of an error.
defer runtime.UnlockOSThread()

// Get everything after "coder agent-exec --"
args := execArgs(os.Args)
if len(args) == 0 {
Expand Down