fix(docker): use HTTP-first proxy detection in health checks

Health check used OS-level port detection (lsof/ss) which is
unavailable in minimal Alpine containers. Switched to the unified
detectRunningProxy() which tries HTTP first, then session lock,
then port-process as fallback.
This commit is contained in:
Tam Nhu Tran
2026-03-28 17:55:39 -04:00
parent 4536d1e5e3
commit d7a80ed38d
+32 -18
View File
@@ -13,7 +13,7 @@ import {
getAllAuthStatus,
CLIPROXY_DEFAULT_PORT,
} from '../../cliproxy';
import { getPortProcess, isCLIProxyProcess } from '../../utils/port-utils';
import { detectRunningProxy } from '../../cliproxy/proxy-detector';
import type { HealthCheck } from './types';
import { CLIPROXY_MAX_STABLE_VERSION } from '../../cliproxy/platform-detector';
import { isNewerVersion, isVersionFaulty } from '../../cliproxy/binary/version-checker';
@@ -130,36 +130,50 @@ export function checkOAuthProviders(): HealthCheck[] {
/**
* Check CLIProxy port status
*
* Uses unified proxy detection (HTTP check first, then session lock, then
* port-process). This works reliably inside Docker containers where OS-level
* port detection tools (lsof/ss) may be unavailable.
*/
export async function checkCliproxyPort(): Promise<HealthCheck> {
const portProcess = await getPortProcess(CLIPROXY_DEFAULT_PORT);
const status = await detectRunningProxy(CLIPROXY_DEFAULT_PORT);
if (!portProcess) {
return {
id: 'cliproxy-port',
name: 'CLIProxy Port',
status: 'info',
message: `${CLIPROXY_DEFAULT_PORT} free`,
details: 'Proxy not running',
};
}
if (isCLIProxyProcess(portProcess)) {
if (status.running && status.verified) {
return {
id: 'cliproxy-port',
name: 'CLIProxy Port',
status: 'ok',
message: 'CLIProxy running',
details: `PID ${portProcess.pid}`,
details: status.pid ? `PID ${status.pid}` : `Detected via ${status.method}`,
};
}
if (status.running) {
return {
id: 'cliproxy-port',
name: 'CLIProxy Port',
status: 'warning',
message: 'CLIProxy starting',
details: status.pid ? `PID ${status.pid}` : `Detected via ${status.method}`,
};
}
if (status.blocked && status.blocker) {
return {
id: 'cliproxy-port',
name: 'CLIProxy Port',
status: 'warning',
message: `Occupied by ${status.blocker.processName}`,
details: `PID ${status.blocker.pid}`,
fix: `Kill process: kill ${status.blocker.pid}`,
};
}
return {
id: 'cliproxy-port',
name: 'CLIProxy Port',
status: 'warning',
message: `Occupied by ${portProcess.processName}`,
details: `PID ${portProcess.pid}`,
fix: `Kill process: kill ${portProcess.pid}`,
status: 'info',
message: `${CLIPROXY_DEFAULT_PORT} free`,
details: 'Proxy not running',
};
}