Skip to content
Latchkey

Haskell GHC out of memory in CI

GHC ran out of memory while compiling, or the OS OOM killer terminated it. Heavy optimization of a large module, parallel builds, or type-level code can exceed a runner with limited RAM.

What this error means

A build fails with "ghc: out of memory (requested ... bytes)", "failed to allocate", or a step that ends abruptly with the process "Killed" (exit 137) during compilation.

Haskell
ghc: out of memory (requested 1048576 bytes)
<no location info>: error:
    ghc: out of memory
Process exited with code: ExitFailure 251

Common causes

Optimization of a large module exceeds RAM

Compiling a big module at -O2, or with heavy type-level computation, can use more memory than a small runner provides.

Too much build parallelism

Building many packages or modules at once multiplies peak memory and tips the runner into OOM.

How to fix it

Cap the GHC heap and reduce parallelism

  1. Limit the GHC RTS heap with +RTS -M so it fails gracefully or stays bounded.
  2. Reduce build jobs so peak memory is lower.
  3. Re-run the build.
Terminal
cabal build all --ghc-options="+RTS -M3g -RTS" -j1

Lower the optimization level for CI

Build heavy modules at a lower optimization level to cut compile-time memory.

Terminal
stack build --fast

How to prevent it

  • Cap the GHC heap and build jobs on memory-limited runners.
  • Use lower optimization in CI where runtime speed does not matter.
  • Cache build artifacts so fewer modules recompile per run.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →