Skip to content

Commit

Permalink
Fix kill id missing
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasz-grz committed Jan 21, 2025
1 parent 52416a8 commit d9ee2d0
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions nat-lab/tests/utils/tcpdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ def __init__(
self.count = count
self.stdout = ""
self.stderr = ""
self.kill_id = (
"DO_NOT_KILL" + secrets.token_hex(8).upper() if session else None,
)
self.kill_id = "DO_NOT_KILL" + secrets.token_hex(8).upper() if session else None

self.output_notifier.notify_output("listening on", self.start_event)

Expand Down Expand Up @@ -141,9 +139,14 @@ async def run(self) -> AsyncIterator["TcpDump"]:
except TimeoutError as e:
print("tcpdump timed out, killing it to create a coredump 🗡️")
if self.connection.target_os != TargetOS.Windows:
await self.connection.create_process(
["kill", "-11", str(self.kill_id)]
).execute()
if self.kill_id:
await self.connection.create_process(
["kill", "-11", str(self.kill_id)]
).execute()
else:
await self.connection.create_process(
["killall", "-11", "tcpdump"]
).execute()
raise TimeoutError from e
yield self
# Windump takes so long to flush packets to stdout/file
Expand Down

0 comments on commit d9ee2d0

Please sign in to comment.