Skip to content

Commit 50507eb

Browse files
jrvb-rlclaude
andauthored
fix: update test script to work without lsof on CI (#798)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3c483bd commit 50507eb

1 file changed

Lines changed: 35 additions & 2 deletions

File tree

scripts/test

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,43 @@ function steady_is_running() {
1313
curl --silent "http://127.0.0.1:4010/_x-steady/health" >/dev/null 2>&1
1414
}
1515

16+
find_pids_on_port_via_proc() {
17+
# Parse /proc/net/tcp{,6} to find socket inodes listening on the port,
18+
# then scan /proc/*/fd/ to find which pids own those sockets.
19+
local port_hex
20+
port_hex=$(printf '%04X' "$1")
21+
local inodes
22+
inodes=$(awk -v ph="$port_hex" '$2 ~ ":"ph"$" && $4 == "0A" {print $10}' /proc/net/tcp /proc/net/tcp6 2>/dev/null | sort -u)
23+
[ -z "$inodes" ] && return
24+
local pids=""
25+
for inode in $inodes; do
26+
for fd in /proc/[0-9]*/fd/*; do
27+
if [ "$(readlink "$fd" 2>/dev/null)" = "socket:[$inode]" ]; then
28+
local pid="${fd#/proc/}"
29+
pid="${pid%%/fd/*}"
30+
pids="$pids $pid"
31+
break
32+
fi
33+
done
34+
done
35+
echo "$pids" | xargs
36+
}
37+
1638
kill_server_on_port() {
17-
pids=$(lsof -t -i tcp:"$1" || echo "")
39+
if command -v lsof >/dev/null 2>&1; then
40+
pids=$(lsof -t -i tcp:"$1" || echo "")
41+
elif command -v ss >/dev/null 2>&1; then
42+
pids=$(ss -tlnp "sport = :$1" 2>/dev/null | grep -oP 'pid=\K[0-9]+' || echo "")
43+
elif command -v fuser >/dev/null 2>&1; then
44+
pids=$(fuser "$1/tcp" 2>/dev/null || echo "")
45+
elif [ -d /proc/net ]; then
46+
pids=$(find_pids_on_port_via_proc "$1")
47+
else
48+
echo "Warning: no tool available to find processes on port $1"
49+
return
50+
fi
1851
if [ "$pids" != "" ]; then
19-
kill "$pids"
52+
kill $pids
2053
echo "Stopped $pids."
2154
fi
2255
}

0 commit comments

Comments
 (0)