When building Go projects on CircleCI using the Docker executor, memory issues can occur because:
- Go will try to optimize according to the number of cores reported on the system.
- The environment will report the number of cores on the VM rather than the available cores for the container.
This can cause Go to spawn too many workers and use all the available memory.
You can control the maximum number of OS threads that are executing code simultaneously, by setting the
GOMAXPROCS variable to the number of cores available to your job.
For example, if you're using the default resource class (medium) for Docker executor jobs (which has 2 cores available):
- image: circleci/golang:1.12
To learn more about how to control the run-time behavior of Go programs, see the GoLang documentation.