(More) Control of the limits of the task container
What challenge are you facing?
I have a set of tests that require more file handlers than the default setup of 1024 that currently the concourse containers run with.
We as well want to have the ability to change the core file size kernel limit. We are interested in this because our developers want the ability to hijack a container and core dump processes with a large memory footprint. In addition the product that they are developing already emits very large core dump files when it encounters an error, and those files are currently getting truncated.
What would make this better?
Technical bits
In our digging we know that the task processes are inheriting it from the garden process which in turn eventually gets it inherited from the VM's init process, which gets the defaults from the kernel. This means that we have to lean on setting those params with garden, which it can do.
For any non-login process the kernel has hard coded defaults. These limits are set for the init process and can be viewed with cat /proc/1/limits. Every other process inherits its limits from its parent unless it makes a call to the os to modify its own limits with setrlimit(). This means that if no intervention is taken, core file size will set the container to have soft limit 0 and hard limit unlimited. Garden does have the ability to take a json struct to modify these limits for the containers it spawns, but Concourse does not take advantage of that when spinning up containers.
Proposed Feature
This feature could look like an addition to some of the currently implemented values that get passed through to Garden:
container_limits:
cpu: 256
memory: 200mb
file-max: 7000
core-dumps: "* soft core unlimited"
This may just be addition to the code here:
https://github.com/concourse/concourse/blob/master/atc/worker/container_spec.go#L79-L99
In absence of this feature there are other options that we want to call out for reference:
Options for others fellow Ops folks in the same boat
- This line at the top of any task script that runs a process that will need a core dump in a concourse container.
# Set to unlimited
ulimit -c unlimited
# Verify core file size
ulimit -c
# Verify all limits
ulimit -a
Note that this assumes the base OS doesn't have some hard limits in place, which currently the bosh stemcells do not but that could always change. This is the standard Linux OS sysadmin limits caveat.
- Set limits for the container in the necessary places of
/etc/security/limits.confand usually/etc/security/limits.d/[something above 20-nproc from PAM]as well. Then in a task script switch user to any user. It doesn't matter what user, you just need to create a login shell withsu foo.
For reference a test that shows the difference in the behavior (run this from a hijacked container or in a task script)
If you have made the suggested changes from above to an image, the below should show those changes taking effect.
echo "ulimit for core file size as seen by concourse task: $(ulimit -c)"
echo "ulimit for core file size if we force a login: $(sudo -u root bash -c "ulimit -c")"
~~Bad~~ Fun things can be done:
-
Use
prlimit(userland tool that wrapsgetrlimit()/setrlimit()which is done with the kernel functionprlimit()) to modify running processes (garden and the containers that inherits its limits) - Note: this can possibly require an upgrade of the bosh stemcells used, because some stemcells (depending on the Ubuntu version) don't come withlinux-utils >2.21that providesprlimit. Refer to this -
Use gdb like this to modify the parent process of all containers on the workers. This is untested because our GDB foo is weak.
-
Patch the kernel. Very untested, but the coolest option, right???
Are you interested in implementing this yourself?
Yes, but we lack the context to know how to implement it completely, how to test it, and changing things like documentation for the new feature.
Issue Bankruptcy
This issue is being closed as part of 2025's Issue Bankruptcy declaration. See here for details
If you think this issue still has merit then feel free to open a new issue and reference this one.