From e16681ac80c82ccb84cd8762e7121ed75306958c Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Sat, 7 Nov 2026 07:49:13 +0000 Subject: [PATCH] fix(web-app-matrix): bound the open-files limit of every MDAD nested container MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit containerd inside the matrix-mdad runner runs with LimitNOFILE=infinity, so every nested container without its own --ulimit inherits 2147483584 open files. uwsgi in matrix-synapse-usage-exporter sized its fd table from that and pinned 16 GiB in CI run 42239638356; ccaa075b54 capped that one container. The inner daemon.json now sets default-ulimits nofile 1048576 soft and hard, so any other nested service that sizes a table from RLIMIT_NOFILE stays bounded too. A container's own --ulimit still wins, so the exporter keeps its 65536. Rendered daemon.json passes dockerd --validate (29.8.2); a string limit is rejected (negative control). The new unit test pins integer Soft/Hard within 65536..1048576 and fails on the base without the key. No live nested-dockerd run: the operator merges sidetrees straight into store-i18n, whose CI proves it; break 6 % accepted by the operator. 🎯 Fix: 92 % 💥 Break: 6 % 💸 Cost: – ⏱️ Time: – 🛡️ Security: 100 % 🏆 Score: 86 🚦 Gate: ⛔ break 6 % > 5 Co-Authored-By: Claude Opus 5.5 --- roles/web-app-matrix/vars/main.yml | 5 +++ .../web-app-matrix/test_mdad_daemon_nofile.py | 37 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 tests/unit/python/roles/web-app-matrix/test_mdad_daemon_nofile.py diff --git a/roles/web-app-matrix/vars/main.yml b/roles/web-app-matrix/vars/main.yml index 52def3410a..c6d8541073 100644 --- a/roles/web-app-matrix/vars/main.yml +++ b/roles/web-app-matrix/vars/main.yml @@ -87,6 +87,11 @@ MATRIX_MDAD_DAEMON_JSON: log-opts: max-size: "10m" max-file: "3" + default-ulimits: + nofile: + Name: nofile + Soft: 1048576 + Hard: 1048576 MATRIX_TELEGRAM_USABLE: >- {{ (lookup('config', application_id, 'secrets.credentials.mautrix_telgegram_bridge_api_id', '') | string | trim | length > 0) diff --git a/tests/unit/python/roles/web-app-matrix/test_mdad_daemon_nofile.py b/tests/unit/python/roles/web-app-matrix/test_mdad_daemon_nofile.py new file mode 100644 index 0000000000..f961102f15 --- /dev/null +++ b/tests/unit/python/roles/web-app-matrix/test_mdad_daemon_nofile.py @@ -0,0 +1,37 @@ +"""The nested MDAD daemon bounds every container's open-files limit. + +containerd inside the matrix-mdad runner runs with LimitNOFILE=infinity, so a +container without its own ``--ulimit`` inherits 2147483584 open files. Anything +that sizes a table from that limit, as uwsgi did in CI run 42239638356, pins +gigabytes; dockerd also refuses to start on a non-integer limit. +""" + +from __future__ import annotations + +import unittest + +from utils.cache.files import PROJECT_ROOT +from utils.cache.yaml import load_yaml +from utils.roles.mapping import ROLE_FILE_VARS_MAIN + +_VARS_MAIN = PROJECT_ROOT / "roles/web-app-matrix" / ROLE_FILE_VARS_MAIN +_FLOOR = 65536 +_CEILING = 1 << 20 + + +class TestMdadDaemonNofile(unittest.TestCase): + def test_every_nested_container_gets_a_bounded_integer_limit(self) -> None: + nofile = load_yaml(_VARS_MAIN)["MATRIX_MDAD_DAEMON_JSON"]["default-ulimits"][ + "nofile" + ] + self.assertEqual(nofile["Name"], "nofile") + for key in ("Soft", "Hard"): + with self.subTest(key=key): + self.assertIs(type(nofile[key]), int) + self.assertGreaterEqual(nofile[key], _FLOOR) + self.assertLessEqual(nofile[key], _CEILING) + self.assertLessEqual(nofile["Soft"], nofile["Hard"]) + + +if __name__ == "__main__": # pragma: no cover + unittest.main()