Skip to content

Commit 25ff4bf

Browse files
committed
fix(test): kill uffd handler when microvm gets killed
By not killing the uffd handler, we are leaking the resources associated with the uffd handler, which can be undesirable and cose gradual slowdown in in snapshot performance tests that restore snapshots using uffd in a loop. Reported-by: Nikita Kalyazin <[email protected]> Signed-off-by: Patrick Roy <[email protected]>
1 parent 4f26549 commit 25ff4bf

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

tests/framework/microvm.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,9 @@ def kill(self):
341341
stderr == "" and "firecracker" not in stdout
342342
), f"Firecracker reported its pid {self.firecracker_pid}, which was killed, but there still exist processes using the supposedly dead Firecracker's jailer_id: {stdout}"
343343

344+
if self.uffd_handler and self.uffd_handler.is_running():
345+
self.uffd_handler.kill()
346+
344347
# Mark the microVM as not spawned, so we avoid trying to kill twice.
345348
self._spawned = False
346349
self._killed = True

tests/framework/utils_uffd.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,22 @@ def log_data(self):
7777
return ""
7878
return self.log_file.read_text(encoding="utf-8")
7979

80+
def kill(self):
81+
"""Kills the uffd handler process"""
82+
assert self.is_running()
83+
84+
self.proc.kill()
85+
86+
def mark_killed(self):
87+
"""Marks the uffd handler as already dead"""
88+
assert not self.is_running()
89+
90+
self._proc = None
91+
8092
def __del__(self):
8193
"""Tear down the UFFD handler process."""
82-
if self.proc is not None:
83-
self.proc.kill()
94+
if self.is_running():
95+
self.kill()
8496

8597

8698
def spawn_pf_handler(vm, handler_path, jailed_snapshot):

tests/integration_tests/functional/test_uffd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,4 @@ def test_malicious_handler(uvm_plain, snapshot):
128128
)
129129
assert False, "Firecracker should freeze"
130130
except (TimeoutError, requests.exceptions.ReadTimeout):
131-
pass
131+
vm.uffd_handler.mark_killed()

0 commit comments

Comments
 (0)