Go cgo "exec gcc: signal: killed" (OOM) - Fix in CI
cgo spawns gcc/clang to compile the C side of a package. A large translation unit on a small runner can exhaust RAM, and the kernel OOM killer sends SIGKILL - surfacing as "signal: killed".
What this error means
A cgo build fails with exec: "gcc": signal: killed or the compiler dies with no diagnostic. Memory pressure on a small runner caused the kernel to kill the compiler process.
go
# example.com/app/native
cgo: C compiler "gcc" failed: exit status 1
exec: "gcc": signal: killedCommon causes
Runner ran out of memory
A heavy C compilation exceeded available RAM and the OOM killer terminated gcc with SIGKILL.
Too much build parallelism
Many gcc processes ran at once via -p, multiplying peak memory beyond what the runner has.
How to fix it
Lower build parallelism
- Cap the number of concurrent compile actions so peak memory stays bounded.
shell
go build -p 2 ./...Build on a larger runner
- Move the cgo-heavy job to a runner with more RAM so the compiler is not killed.
.github/workflows/ci.yml
jobs:
build:
runs-on: latchkey-largeHow to prevent it
- Size cgo-heavy jobs onto runners with adequate RAM.
- Cap -p so concurrent gcc processes do not multiply memory use.
- Watch peak memory of native builds and split large C units.
Related guides
Go cgo "undefined reference" (C link) - Fix in CIFix Go cgo "undefined reference to" link errors in CI - the linker could not find a C symbol because the libr…
Go "relocation truncated to fit" - Fix in CIFix Go "relocation truncated to fit" link errors in CI - a cgo binary exceeded the small/medium code-model ra…
Go "too many open files" (ulimit) - Fix in CIFix Go build/test "too many open files" in CI - the process hit the file-descriptor ulimit. Raise the limit o…