Skip to content

Commit 8a68d68

Browse files
committed
refactor: update netstat command and improve wait logic
- Simplified netstat command to use `netstat -plnt` for listening services - Removed unnecessary shell execution in netstat command - Adjusted wait logic for closing connections in TIME_WAIT state - Increased sleep duration to ensure connections are properly closed
1 parent 5b3faa9 commit 8a68d68

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

cardano_node_tests/cluster_management/netstat_tools.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
def get_netstat_listen() -> str:
1616
"""Get listing of listening services from the `netstat` command."""
1717
try:
18-
return helpers.run_command(
19-
"netstat -pant | grep -E 'LISTEN|TIME_WAIT'", ignore_fail=True, shell=True
20-
).decode()
18+
return helpers.run_command("netstat -plnt", ignore_fail=True).decode()
2119
except Exception as excp:
2220
LOGGER.error(f"Failed to fetch netstat output: {excp}") # noqa: TRY400
2321
return ""
@@ -91,7 +89,7 @@ def _get_proc_cmdline(pid: int) -> str:
9189
time.sleep(5)
9290
break
9391

94-
# Kill all the leftover processes, if possible, and wait for them to finish
92+
# Kill all the leftover processes
9593
for _ in range(5):
9694
found = False
9795
for line in _get_listen_split():
@@ -108,14 +106,15 @@ def _get_proc_cmdline(pid: int) -> str:
108106
if not found:
109107
break
110108

111-
# Wait until all connections are closed
112-
for _ in range(3):
109+
# Wait until all connections are closed.
110+
# The connection can be in TIME_WAIT state for 60 sec.
111+
for _ in range(6):
113112
found = False
114113
for line in _get_conn_split():
115114
if not ports_re.search(line):
116115
continue
117116
found = True
118-
time.sleep(5)
117+
time.sleep(10)
119118
break
120119
if not found:
121120
break

0 commit comments

Comments
 (0)