Skip to content

Conversation

@JakobLichterfeld
Copy link
Member

@JakobLichterfeld JakobLichterfeld commented Nov 5, 2025

On certain systems (e.g., Debian 13 with modern container runtimes), a very high default nofiles ulimit can cause the Erlang VM (beam.smp) to pre-allocate excessive amounts of memory, leading to container crashes.

This change introduces a safeguard directly into the entrypoint script:

  • It caps the soft ulimit -n to a configurable maximum, defined by the ULIMIT_MAX_NOFILE environment variable (defaults to 65536).
  • This behavior can be disabled by setting ULIMIT_MAX_NOFILE=0.
  • The new environment variable has been added to the documentation.

To satisfy ShellCheck (SC3045), the script's shebang is set to #!/usr/bin/env dash, as ulimit -n is a common but not strictly POSIX-compliant extension.
For consistency with the entrypoint.sh script's shebang (#!/usr/bin/env dash), this change updates the Dockerfile's ENTRYPOINT to call /bin/dash directly instead of /bin/sh.

fixes #4940 and related to #3045.

successor of #4999. Thanks @dyxyl for your work on this.

Architecture decision

Rather than changing the documentation to set up the host correctly, this change means that users do not need to update their Docker Compose files. This results in fewer tickets about memory bloat, because users did not follow the latest documentation.

…rsions of Docker/containerd Hosts (e.g. on Debian 13)

On certain systems (e.g., Debian 13 with modern container runtimes), a very high default `nofiles` ulimit can cause the Erlang VM (beam.smp) to pre-allocate excessive amounts of memory, leading to container crashes.

This change introduces a safeguard directly into the entrypoint script:
- It caps the soft `ulimit -n` to a configurable maximum, defined by the `ULIMIT_MAX_NOFILE` environment variable (defaults to 65536).
- This behavior can be disabled by setting `ULIMIT_MAX_NOFILE=0`.
- The new environment variable has been added to the documentation.

To satisfy ShellCheck (SC3045), the script's shebang is set to `#!/usr/bin/env dash`, as `ulimit -n` is a common but not strictly POSIX-compliant extension.
For consistency with the `entrypoint.sh` script's shebang (`#!/usr/bin/env dash`), this change updates the Dockerfile's ENTRYPOINT to call `/bin/dash` directly instead of `/bin/sh`.

This makes the choice of shell explicit and ensures the script is always executed by the intended interpreter, regardless of what `/bin/sh` might point to in future base images.
@netlify
Copy link

netlify bot commented Nov 5, 2025

Deploy Preview for teslamate ready!

Name Link
🔨 Latest commit 302475d
🔍 Latest deploy log https://app.netlify.com/projects/teslamate/deploys/690b726160310b0007a0a274
😎 Deploy Preview https://deploy-preview-5025--teslamate.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@JakobLichterfeld
Copy link
Member Author

After merging this, I will merge #4890 and do the next release, see discussion here

Copy link
Collaborator

@swiffer swiffer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confirmed to be applied by default and skipped when setting the env var to 0.

tested this pr and inspected ulimit via:

docker exec -it teslamate-teslamate-1 cat /proc/*/limits | grep "Max open files"

@swiffer swiffer merged commit 302475d into main Nov 5, 2025
24 checks passed
@swiffer swiffer deleted the feat-Avoid-memory-bloat-in-misconfigured-docker-hosts branch November 5, 2025 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot allocate 2147483711 bytes of memory

3 participants