Search code examples
code-coveragebazeltest-coveragebazel-java

bazel running out of memory and crashing when running coverage


When running Bazel coverage on service code, it is crashing on Jenkins pods and also local mac. I want to know does Bazel provide any run efficiency flags to be used in these cases where time does not matter and tests can run in series instead of parallel?

what are recommendations in Bazel params when it ends up with error below?.

Jenkins pods has a limit of pod memory that is max 32GB iiuc.

so is there an optimal combo of params to be used to get this to completion?

FATAL: bazel ran out of memory and crashed. Printing stack trace:
[182,301 / 182,393] 5 / 38 tests, 3 failed; [Prepa] BuildStorybook src/ui/storybook-build; 1958s ... (18 actions, 10 running)
[182,301 / 182,393] 5 / 38 tests, 3 failed; [Prepa] BuildStorybook src/ui/storybook-build; 2286s ... (18 actions, 10 running)

FATAL: bazel ran out of memory and crashed. Printing stack trace:
java.lang.OutOfMemoryError: Java heap space

my run parameters were

./bazel coverage --config=gocov //src/ui/... \
        --collect_code_coverage \
        --combined_report=lcov \
        --remote_download_minimal \
        --coverage_report_generator="//src/cmd/gocoverage-lcov:gocoverage-lcov"

pod resources maxed out.

      resources:
        requests:
          memory: 32Gi
          cpu: 18
        limits:
          memory: 48Gi
          cpu: 24

Solution

  • There are different ways how you can limit the resource usage of Bazel, e.g. number of parallel jobs:

    bazel build --jobs=2 //foo:bar
    

    Similar questions were already asked.