Skip to content

Commit 1538710

Browse files
committed
fix(test): do no cause secondary errors in _dump_debug_info
If firecracker already died, then the pid file might not exist anymore, and we get a NoSuchProcess exception from thread_backtraces(). This can be confusing when debugging failures, because its a secondary error that only happens during error handling of the actual reason we're dumping debug information in the first place. Fix this by simply returning an empty list of threads in this case. Signed-off-by: Patrick Roy <[email protected]>
1 parent 713bf0a commit 1538710

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

tests/framework/microvm.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,10 +1101,12 @@ def thread_backtraces(self):
11011101
backtraces = []
11021102
for thread_name, thread_pids in utils.get_threads(self.firecracker_pid).items():
11031103
for pid in thread_pids:
1104-
backtraces.append(
1105-
f"{thread_name} ({pid=}):\n"
1106-
f"{utils.check_output(f'cat /proc/{pid}/stack').stdout}"
1107-
)
1104+
try:
1105+
stack = Path(f"/proc/{pid}/stack").read_text("UTF-8")
1106+
except FileNotFoundError:
1107+
continue # process might've gone away between get_threads() call and here
1108+
1109+
backtraces.append(f"{thread_name} ({pid=}):\n{stack}")
11081110
return "\n".join(backtraces)
11091111

11101112
def _dump_debug_information(self, what: str):

tests/framework/utils.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,15 @@
3434

3535
def get_threads(pid: int) -> dict:
3636
"""Return dict consisting of child threads."""
37-
threads_map = defaultdict(list)
38-
proc = psutil.Process(pid)
39-
for thread in proc.threads():
40-
threads_map[psutil.Process(thread.id).name()].append(thread.id)
41-
return threads_map
37+
try:
38+
proc = psutil.Process(pid)
39+
40+
threads_map = defaultdict(list)
41+
for thread in proc.threads():
42+
threads_map[psutil.Process(thread.id).name()].append(thread.id)
43+
return threads_map
44+
except psutil.NoSuchProcess:
45+
return {}
4246

4347

4448
def get_cpu_affinity(pid: int) -> list:

0 commit comments

Comments
 (0)