Skip to content

Commit ad17dac

Browse files
committed
Reduce PID limits for test_forkbomb_resource_unavailable
This test case was being caught and nsjail was killing it, but not because of PID exhaustion but memory exhaustion. To ensure PID exhaustion is guarded against the PID count is now reduced to a level where nsjail will kill the process earlier before the memory limit.
1 parent dfebd21 commit ad17dac

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

tests/test_nsjail.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,13 @@ def test_write_hidden_exclude(self):
213213
self.assertEqual(result.files[0].content, b"a")
214214

215215
def test_forkbomb_resource_unavailable(self):
216+
# Using the production max PIDs causes processes to be killed due to memory instead of
217+
# PID allocation exhaustion. For this test case, the PID limit is reduced to ensure
218+
# that PID exhaustion is still something that is guarded against.
219+
220+
previous_pids_max = self.nsjail.config.cgroup_pids_max
221+
self.nsjail.config.cgroup_pids_max = 5
222+
216223
code = dedent(
217224
"""
218225
import os
@@ -221,10 +228,13 @@ def test_forkbomb_resource_unavailable(self):
221228
"""
222229
).strip()
223230

224-
result = self.eval_file(code)
225-
self.assertEqual(result.returncode, 1)
226-
self.assertIn("Resource temporarily unavailable", result.stdout)
227-
self.assertEqual(result.stderr, None)
231+
try:
232+
result = self.eval_file(code)
233+
self.assertEqual(result.returncode, 1)
234+
self.assertIn("Resource temporarily unavailable", result.stdout)
235+
self.assertEqual(result.stderr, None)
236+
finally:
237+
self.nsjail.config.cgroup_pids_max = previous_pids_max
228238

229239
def test_file_parsing_timeout(self):
230240
code = dedent(

0 commit comments

Comments
 (0)