Docker, rust, cargo and 137 Errors

I kept getting OOMKilled when trying to build Rust apps in Docker containers on GitHub Actions (and also locally, using buildx). The return code of any cargo command that touched the list of crates would end up with the command killed after 30-90 seconds.

I found two solutions:

Use nightly and use the sparse-registry option.

  • Tracking Issue: 9069
  • RFC: #2789 The sparse-registry feature allows cargo to interact with remote registries served over plain HTTP rather than git. These registries can be identified by urls starting with sparse+http:// or sparse+https://.

When fetching index metadata over HTTP, Cargo only downloads the metadata for relevant crates, which can save significant time and bandwidth.

Set net.git-fetch-with-cli = true

Referenced in this Comment on a bug report.

net.git-fetch-with-cli

Type: boolean Default: false Environment: CARGO_NET_GIT_FETCH_WITH_CLI If this is true, then Cargo will use the git executable to fetch registry indexes and git dependencies. If false, then it uses a built-in git library.

Adding a line of ENV CARGO_NET_GIT_FETCH_WITH_CLI=true in the Dockerfile sorted it.

I found the nightly one first, and I really like it because it’s super fast compared to the usual “pull the entire crates ref and then work it out” method. Sadly, nightly’s not exactly the best place to be, so the other one’s the method I went with for now.



#docker #rust #cargo #error #github actions