Skip to content

Commit d8d3001

Browse files
committed
fix(e2e): add lsof/ps debugging when serve polling fails
1 parent ba2ebe6 commit d8d3001

1 file changed

Lines changed: 33 additions & 6 deletions

File tree

integration/models/application.ts

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { execSync } from 'node:child_process';
12
import * as path from 'node:path';
23

34
import { parsePublishableKey } from '@clerk/shared/keys';
@@ -161,6 +162,7 @@ export const application = (
161162
return { port, serverUrl: runtimeServerUrl };
162163
}
163164

165+
log(`Running serve command: "${scripts.serve}" with PORT=${port}, detached=${opts.detached}`);
164166
const proc = run(scripts.serve, {
165167
cwd: appDirPath,
166168
env: { PORT: port.toString() },
@@ -174,21 +176,46 @@ export const application = (
174176
log(msg);
175177
},
176178
});
179+
log(`Serve process spawned: pid=${proc.pid}`);
177180

178181
if (opts.detached) {
179182
proc.on('exit', (code, signal) => {
180183
log(`Serve process exited: code=${code}, signal=${signal}`);
181184
});
182-
const shouldExit = () => !!proc.exitCode && proc.exitCode !== 0;
185+
const shouldExit = () => {
186+
if (proc.exitCode != null) {
187+
log(`Serve process has exitCode=${proc.exitCode}`);
188+
return true;
189+
}
190+
return false;
191+
};
183192
try {
184193
await waitForServer(runtimeServerUrl, { log, maxAttempts: 120, shouldExit });
185194
} catch (e) {
186-
// Dump log files for debugging
195+
// Check what the serve process is actually doing
196+
try {
197+
const lsofOut = execSync(`lsof -i -P -n -p ${proc.pid} 2>&1 || true`, { encoding: 'utf-8' });
198+
log(`lsof for serve pid ${proc.pid}:\n${lsofOut || '(no output)'}`);
199+
} catch {
200+
log(`Could not run lsof for pid ${proc.pid}`);
201+
}
202+
try {
203+
const psOut = execSync('ps aux 2>&1 || true', { encoding: 'utf-8' });
204+
const serveLines = psOut
205+
.split('\n')
206+
.filter(
207+
l =>
208+
l.includes(String(proc.pid)) || l.includes('react-router') || l.includes('vite') || l.includes(String(port)),
209+
);
210+
log(`Related processes:\n${serveLines.join('\n') || '(none found)'}`);
211+
} catch {
212+
log('Could not run ps');
213+
}
187214
try {
188-
const stdout = await fs.readFile(stdoutFilePath, 'utf-8');
189-
const stderr = await fs.readFile(stderrFilePath, 'utf-8');
190-
log(`Serve stdout log:\n${stdout}`);
191-
log(`Serve stderr log:\n${stderr}`);
215+
const stdoutContent = await fs.readFile(stdoutFilePath, 'utf-8');
216+
const stderrContent = await fs.readFile(stderrFilePath, 'utf-8');
217+
log(`Serve stdout:\n${stdoutContent || '(empty)'}`);
218+
log(`Serve stderr:\n${stderrContent || '(empty)'}`);
192219
} catch {
193220
log('Could not read serve log files');
194221
}

0 commit comments

Comments
 (0)