Skip to content

Commit 61608a2

Browse files
sarroutbiclaude
andcommitted
Add comprehensive port 3001 debugging and logging
Enhanced the Mockoon CI testing infrastructure with extensive debugging capabilities to diagnose port conflicts and process issues. Changes to tests/mockoon_registrar_tests.sh: - Added log_port_3001_info() function that captures detailed information: * Process IDs, commands, users, parent PIDs, start times * Working directories and environment variables * Network socket information (lsof, netstat, ss) * Docker container status and systemd services * HTTP connectivity tests and response headers - Enhanced cleanup logic with before/after logging - Made the script resilient to missing system tools Changes to .github/workflows/mockoon.yaml: - Added pre-Mockoon debugging step to capture baseline system state - Added post-Mockoon debugging step to verify Mockoon startup - Logs available system tools, network state, processes, and environment - Provides comprehensive visibility into CI environment This will help diagnose any future port conflicts or process management issues in the CI environment, making debugging much more efficient. Co-Authored-By: Claude <[email protected]> Signed-off-by: Sergio Arroutbi <[email protected]>
1 parent 8c4e6ab commit 61608a2

File tree

2 files changed

+164
-1
lines changed

2 files changed

+164
-1
lines changed

.github/workflows/mockoon.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,68 @@ jobs:
3535
- uses: actions/checkout@v5
3636
- name: NPM installation
3737
run: dnf install -y npm
38+
- name: Pre-Mockoon system debugging
39+
run: |
40+
echo "======== PRE-MOCKOON SYSTEM STATE ========"
41+
echo "Available system tools:"
42+
command -v lsof && echo "✓ lsof available" || echo "✗ lsof not available"
43+
command -v netstat && echo "✓ netstat available" || echo "✗ netstat not available"
44+
command -v ss && echo "✓ ss available" || echo "✗ ss available"
45+
command -v curl && echo "✓ curl available" || echo "✗ curl not available"
46+
command -v docker && echo "✓ docker available" || echo "✗ docker not available"
47+
48+
echo ""
49+
echo "Current processes using port 3001 (should be none):"
50+
lsof -i :3001 2>/dev/null || echo "No processes using port 3001"
51+
52+
echo ""
53+
echo "All listening ports:"
54+
netstat -tulpn 2>/dev/null | head -20 || ss -tulpn 2>/dev/null | head -20 || echo "Cannot list ports"
55+
56+
echo ""
57+
echo "Current user and environment:"
58+
echo "User: $(whoami)"
59+
echo "UID: $(id -u)"
60+
echo "Groups: $(id -G)"
61+
echo "HOME: $HOME"
62+
echo "PWD: $PWD"
63+
echo "CI: ${CI:-not_set}"
64+
echo "GITHUB_ACTIONS: ${GITHUB_ACTIONS:-not_set}"
65+
66+
echo ""
67+
echo "Container/system info:"
68+
echo "Hostname: $(hostname)"
69+
uname -a
70+
cat /etc/os-release | head -5
71+
echo "======== END PRE-MOCKOON SYSTEM STATE ========"
3872
- name: Run Mockoon CLI
3973
uses: mockoon/cli-action@v2
4074
with:
4175
version: latest
4276
data-file: keylime-push-model-agent/test-data/registrar.json
4377
port: 3001
78+
- name: Post-Mockoon system debugging
79+
run: |
80+
echo "======== POST-MOCKOON SYSTEM STATE ========"
81+
echo "Processes using port 3001 after Mockoon start:"
82+
lsof -i :3001 2>/dev/null || echo "No processes using port 3001 (unexpected!)"
83+
84+
echo ""
85+
echo "Mockoon-related processes:"
86+
ps aux | grep -i mockoon | grep -v grep || echo "No mockoon processes found"
87+
88+
echo ""
89+
echo "Node.js processes:"
90+
ps aux | grep -E "(node|npm)" | grep -v grep || echo "No node/npm processes found"
91+
92+
echo ""
93+
echo "Test HTTP connectivity to port 3001:"
94+
curl -sI --connect-timeout 5 http://localhost:3001 2>/dev/null || echo "Failed to connect to port 3001"
95+
96+
echo ""
97+
echo "Network connections:"
98+
netstat -tulpn 2>/dev/null | grep ':3001' || ss -tulpn 2>/dev/null | grep ':3001' || echo "No port 3001 connections found"
99+
echo "======== END POST-MOCKOON SYSTEM STATE ========"
44100
- name: Set git safe.directory for the working directory
45101
run: git config --system --add safe.directory "$PWD"
46102
- name: Mockoon registrar tests custom script execution

tests/mockoon_registrar_tests.sh

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,98 @@ fi
3030

3131
mkdir -p /var/lib/keylime
3232

33+
# Function to log detailed information about port 3001 usage
34+
log_port_3001_info() {
35+
echo "======== DETAILED PORT 3001 ANALYSIS ========"
36+
echo "Timestamp: $(date)"
37+
echo "Environment: CI=${CI:-false}, GITHUB_ACTIONS=${GITHUB_ACTIONS:-false}"
38+
echo ""
39+
40+
echo "--- lsof output for port 3001 ---"
41+
if command -v lsof >/dev/null 2>&1; then
42+
lsof -i :3001 2>/dev/null || echo "No lsof results for port 3001"
43+
echo ""
44+
echo "--- lsof with process details ---"
45+
lsof -i :3001 -P -n 2>/dev/null || echo "No detailed lsof results"
46+
else
47+
echo "lsof command not available"
48+
fi
49+
echo ""
50+
51+
echo "--- netstat output ---"
52+
if command -v netstat >/dev/null 2>&1; then
53+
netstat -tulpn 2>/dev/null | grep ':3001' || echo "No netstat results for port 3001"
54+
else
55+
echo "netstat command not available"
56+
fi
57+
echo ""
58+
59+
echo "--- ss (socket statistics) output ---"
60+
if command -v ss >/dev/null 2>&1; then
61+
ss -tulpn 2>/dev/null | grep ':3001' || echo "No ss results for port 3001"
62+
else
63+
echo "ss command not available"
64+
fi
65+
echo ""
66+
67+
echo "--- Process tree and details ---"
68+
if lsof -i :3001 >/dev/null 2>&1; then
69+
echo "Processes using port 3001:"
70+
for pid in $(lsof -ti :3001 2>/dev/null); do
71+
echo " PID: $pid"
72+
if [ -d "/proc/$pid" ]; then
73+
echo " Command: $(cat /proc/$pid/comm 2>/dev/null || echo 'N/A')"
74+
echo " Cmdline: $(cat /proc/$pid/cmdline 2>/dev/null | tr '\0' ' ' || echo 'N/A')"
75+
echo " User: $(stat -c '%U' /proc/$pid 2>/dev/null || echo 'N/A')"
76+
echo " Parent PID: $(cat /proc/$pid/stat 2>/dev/null | awk '{print $4}' || echo 'N/A')"
77+
echo " Start time: $(stat -c '%Y' /proc/$pid 2>/dev/null | xargs -I {} date -d @{} 2>/dev/null || echo 'N/A')"
78+
echo " Working directory: $(readlink /proc/$pid/cwd 2>/dev/null || echo 'N/A')"
79+
echo " Environment (filtered):"
80+
grep -E "(MOCKOON|NODE|NPM|PATH|USER|HOME)" /proc/$pid/environ 2>/dev/null | tr '\0' '\n' | sed 's/^/ /' || echo " N/A"
81+
else
82+
echo " Process details not available (proc not mounted or process gone)"
83+
fi
84+
echo ""
85+
done
86+
fi
87+
88+
echo "--- Process list (mockoon related) ---"
89+
ps aux 2>/dev/null | grep -i mockoon | grep -v grep || echo "No mockoon processes found"
90+
echo ""
91+
92+
echo "--- Process list (node related on port 3001) ---"
93+
ps aux 2>/dev/null | grep -E "(node|npm)" | grep -v grep || echo "No node/npm processes found"
94+
echo ""
95+
96+
echo "--- Docker containers (if running in container) ---"
97+
if command -v docker >/dev/null 2>&1 && docker ps >/dev/null 2>&1; then
98+
docker ps | grep -E "(mockoon|3001)" || echo "No docker containers with mockoon or port 3001"
99+
else
100+
echo "Docker not available or not accessible"
101+
fi
102+
echo ""
103+
104+
echo "--- Systemd services (if available) ---"
105+
if command -v systemctl >/dev/null 2>&1; then
106+
systemctl list-units --type=service | grep -i mockoon || echo "No systemd mockoon services"
107+
else
108+
echo "systemctl not available"
109+
fi
110+
echo ""
111+
112+
echo "--- HTTP response test ---"
113+
if curl -s --connect-timeout 2 http://localhost:3001 2>/dev/null; then
114+
echo "HTTP response received from port 3001"
115+
echo "Response headers:"
116+
curl -sI --connect-timeout 2 http://localhost:3001 2>/dev/null || echo "Failed to get headers"
117+
else
118+
echo "No HTTP response from port 3001"
119+
fi
120+
echo ""
121+
122+
echo "======== END PORT 3001 ANALYSIS ========"
123+
}
124+
33125
# Check if Mockoon is already running on port 3001 (e.g., in CI)
34126
# Try multiple methods to detect if port 3001 is in use
35127
PORT_IN_USE=false
@@ -45,6 +137,7 @@ fi
45137

46138
if $PORT_IN_USE; then
47139
echo "-------- Mockoon already running on port 3001 (likely in CI)"
140+
log_port_3001_info
48141
MOCKOON_PID=""
49142
else
50143
# Check if Mockoon is installed for local runs
@@ -106,11 +199,25 @@ if [ -n "$MOCKOON_PID" ]; then
106199
fi
107200

108201
if $PORT_STILL_IN_USE; then
109-
echo "Warning: Port 3001 still in use, forcing cleanup"
202+
echo "Warning: Port 3001 still in use after stopping Mockoon, forcing cleanup"
203+
echo "---- Port 3001 status before cleanup ----"
204+
log_port_3001_info
205+
206+
echo "---- Performing cleanup ----"
110207
lsof -ti :3001 | xargs kill -9 2>/dev/null || true
111208
# Additional cleanup methods
112209
pkill -f "mockoon-cli.*3001" 2>/dev/null || true
113210
pkill -f "node.*mockoon.*3001" 2>/dev/null || true
211+
212+
# Wait a moment and check again
213+
sleep 2
214+
echo "---- Port 3001 status after cleanup ----"
215+
if lsof -i :3001 >/dev/null 2>&1 || netstat -ln 2>/dev/null | grep -q ':3001 ' || ss -ln 2>/dev/null | grep -q ':3001 '; then
216+
echo "WARNING: Port 3001 still in use after cleanup attempts"
217+
log_port_3001_info
218+
else
219+
echo "Port 3001 successfully cleaned up"
220+
fi
114221
fi
115222
else
116223
echo "-------- Mockoon was already running (CI), not stopping it"

0 commit comments

Comments
 (0)