Skip to content

Build killed with exit 137 when several builds run at once

When two or three builds share one computer, the memory killer stops one with exit 137. How to confirm it, cap it, and queue builds so each one finishes.

On this page

Your build worked a minute ago. Now it stops halfway with one word, Killed, and the exit code is 137. You run it again on its own and it passes. Nothing in the code changed. What changed is that two or three other builds or test suites were running on the same computer at the same time, often started by different coding agents.

What exit 137 means

An exit code above 128 means the process was ended by a signal. Subtract 128 to get the signal number. 137 minus 128 is 9, which is SIGKILL. A process cannot catch or clean up after SIGKILL, so the build stops mid-step and prints little or nothing.

Something sent that signal. On a developer machine or a build server, the most common sender is the system itself when memory runs out:

  • Linux has an out-of-memory killer. When the kernel cannot free enough memory, it picks a process, mostly by how much memory it uses, and kills it.
  • Containers (Docker and others) have their own memory limit. When a container passes it, the kernel kills a process inside it; when that is the main process, the container ends with the same exit code.
  • macOS first compresses memory and then swaps, so the computer gets very slow before anything is killed. A build can still end with Killed: 9.

A person or a tool can also send SIGKILL with kill -9. Rule that out before blaming memory.

Why per-tool limits are not enough

Most build tools let you cap their own parallelism: make -j2, Gradle's --max-workers, Jest's --maxWorkers, or Node's --max-old-space-size. Those caps work inside one run. They do not know about the other runs.

If three agents each start npm run build with a sensible cap, you still have three builds. Each one is reasonable on its own. Together they ask for more memory than the machine has. The killer then stops whichever process is largest at that moment, which may be the build that was nearly done.

How to confirm it without any extra tool

  1. Check the exit code. Right after the failure, run echo $?. A value of 137 means SIGKILL.
  2. Look for the kill in the system log.
    • Linux: dmesg -T | grep -i -E "out of memory|killed process" or journalctl -k | grep -i oom. You may need sudo. A line naming your build's process is the proof.
    • Docker: docker inspect --format '{{.State.OOMKilled}}' <container> prints true when the container hit its memory limit.
    • macOS: watch memory_pressure or the Memory Pressure graph in Activity Monitor while the builds run, and check swap with sysctl vm.swapusage.
  3. Measure one build's peak memory. On Linux, /usr/bin/time -v npm run build prints "Maximum resident set size". On macOS, /usr/bin/time -l npm run build prints the same figure in bytes. Multiply by the number of builds that tend to overlap and compare with your RAM.
  4. Count what is running. ps -Ao pid,rss,command | grep -E "build|webpack|vite|tsc|next" shows how many build processes are alive and how much memory each holds.

If one build alone needs more memory than the machine has, the fix is in the build: lower its own worker count, split it, or add memory. If one build fits but three at once do not, the fix is to stop them overlapping.

Fixes that work without a queue

  • Cap each tool's workers so one build leaves room for the rest of the system.
  • Add swap on Linux. It turns a kill into slowness, which is easier to notice.
  • Run builds one at a time by hand. This works until several agents start builds on their own.

The last point is the hard one. Agents do not see each other's runs, so none of them knows to wait.

How dotime-queue helps

dotime-queue is a waiting line for heavy commands on one computer. Every build or test run started through it waits for a free slot, and for the machine to have room, before it starts.

Shell
npm install -g deployontimedotime-queue setup --writedotime-queue run --label "web-app: build" -- npm run build > build.log 2>&1dotime-queue status

setup --write adds one instruction to the project's agent files (AGENTS.md, CLAUDE.md), so agents start their heavy commands through the queue. Without --write it only shows what it would add.

What happens then, by the defaults in the manual:

  • At most 2 jobs run at once. On a computer with more than 5 cores, extra slots up to half the cores are given while the CPU has room.
  • A job waits while free memory is below 20 percent, free disk is below 10 GB, or the load is high while the CPU is busy. These limits live in ~/.dotime/config.json and can be changed. { "slots": 1 } there runs one heavy job at a time.
  • A run ended by a kill signal it did not send is journalled as stopped, not as a failure of your code. When the output went to a file, as in the example above, and shows Killed with exit 137, the run gets the reason class memory. Output to a terminal or a pipe is never read, and the class is then unknown.
  • dotime-queue reasons counts the failures of the last 7 days by class, so you can see how many were memory and not code.

In the project's own benchmark, 4 agents started the same test suite at once on one Mac. Started directly, 400 of 400 tests failed on the first try in every run. Through the queue, 0 of 400 did. The suite is a stand-in, not a real project, and your numbers will differ. Details are on the benchmarks page.

What it does not do

  • It does not make a build smaller. A build that needs more memory than the computer has is killed with or without the queue.
  • The health gate is checked only before a job starts. A running job is never stopped because the computer got busy later.
  • It only holds commands started through dotime-queue run. A build an agent starts directly is not held.
  • It does nothing for cloud build services or CI runners. It runs on your macOS or Linux machine only.
  • It does not fix bugs in your build or your app.