Repository navigation
Conversation
The process wrapper unconditionally ran `echo 100 > /proc/$$/oom_score_adj && exec ...` before every command. An unprivileged process may not lower its OOM score (proc(5)), so in a container that inherits a score above 100 (Docker `--oom-score-adj=993`, a Kubernetes Burstable pod) the write is rejected and the `&&` chain fails the spawn: every command fails with an `echo: I/O error`. Read /proc/self/oom_score_adj in envd -- children inherit it -- and prepend the write only when the inherited score is below the target. Raising is always permitted, and preserving a higher score assigned by the container runtime keeps its OOM protection intact. When the score cannot be read, fall back to the unconditional write, matching the previous behavior.
yjjnls
requested review from
ValentaTomas,
dobrac and
jakubno
as code owners
November 22, 2026 23:27
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3775.
Problem
When envd inherits an
oom_score_adjabove 100 and does not holdCAP_SYS_RESOURCE— e.g. a container started with--oom-score-adj=993, or a Kubernetes Burstable pod — every command fails. The process wrapper prependsecho 100 > /proc/$$/oom_score_adj && exec ..., the shell runs afterSysProcAttr.Credentialhas dropped to the target user, and an unprivileged process may not lower its OOM score (proc(5)). The rejected write aborts the&&chain, so eventruefails withecho: I/O error. This is a total process-spawn outage, not just a lost OOM reset, and it is present in current main and all affected tags.Change
The decision moves into Go at spawn time: envd reads
/proc/self/oom_score_adj(children inherit it) and prepends the write only when the inherited score is below the target (100).-1000, a Guaranteed pod's-997, or0)echo 100 > /proc/$$/oom_score_adj &&--oom-score-adj)/procread failsecho 100 > ... &&keptRaising an OOM score is always permitted for an unprivileged process, and preserving a higher runtime-assigned score is also the semantically correct outcome — the runtime deliberately made these processes more OOM-killable than 100.
Considerations
$(<file)is not POSIX; dash/busybox ash would needcatorread, adding a fork per spawn on the hot path. Reading in Go costs one small/procread per process start and no extra process. The wrapper stays a one-liner./proc/self/oom_score_adjis always readable by the process on Linux, so the fallback matters only where procfs is absent (where the write would fail anyway) and for non-Linux builds of theunixfile. Keeping the write preserves the previous behavior and the OOM protection reset; skipping it would be a silent behavior change in the normal case.oom_score_adj=-1000, which is below the target, so the wrapper still resets children and grandchildren to 100 beforeexecexactly as fix(envd): eliminate OOM score and nice priority race in child processes #2028 intended.os/exec.Cmdcannot run a hook between the credential drop andexec, so an envd that itself runs unprivileged with a score above 100 cannot have its children corrected by any in-child write. With this change that residual case degrades to "children run at the inherited score" instead of "every spawn fails". The nice/ionice legs of the wrapper are unaffected — their deltas only ever move the child to an equal-or-worse priority, which an unprivileged process may always do./procread (a few microseconds) on the existing per-process start path, and one fewer write syscall in the child when the skip branch applies. No change to steady-state or concurrency behavior.Tests
New unit tests in
packages/envd/internal/services/process/handler/spawn_unix_test.gopin the wrapper-prefix semantics at the boundaries: below the target raises (-1000,0,99), at or above the target keeps the inherited score (100,993), unreadable falls back to the unconditional write.Ran locally:
go test -race ./internal/services/process/...— passgo test ./...inpackages/envd— pass; the only failures are pre-existing, environment-dependentfilesystemtests that require thebindfsbinary, unrelated to this changegolangci-lint run(pinned v2.15.0) on the package — 0 issues; formatters cleanNo integration test added: exercising this end to end requires a container/VM spawned with a restricted
oom_score_adjand noCAP_SYS_RESOURCE; the unit tests pin the generated wrapper, which is what decides the behavior.