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()