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, getAllAuthStatus,
CLIPROXY_DEFAULT_PORT, CLIPROXY_DEFAULT_PORT,
} from '../../cliproxy'; } from '../../cliproxy';
import { getPortProcess, isCLIProxyProcess } from '../../utils/port-utils'; import { detectRunningProxy } from '../../cliproxy/proxy-detector';
import type { HealthCheck } from './types'; import type { HealthCheck } from './types';
import { CLIPROXY_MAX_STABLE_VERSION } from '../../cliproxy/platform-detector'; import { CLIPROXY_MAX_STABLE_VERSION } from '../../cliproxy/platform-detector';
import { isNewerVersion, isVersionFaulty } from '../../cliproxy/binary/version-checker'; import { isNewerVersion, isVersionFaulty } from '../../cliproxy/binary/version-checker';
@@ -130,36 +130,50 @@ export function checkOAuthProviders(): HealthCheck[] {
/** /**
* Check CLIProxy port status * 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> { export async function checkCliproxyPort(): Promise<HealthCheck> {
const portProcess = await getPortProcess(CLIPROXY_DEFAULT_PORT); const status = await detectRunningProxy(CLIPROXY_DEFAULT_PORT);
if (!portProcess) { if (status.running && status.verified) {
return {
id: 'cliproxy-port',
name: 'CLIProxy Port',
status: 'info',
message: `${CLIPROXY_DEFAULT_PORT} free`,
details: 'Proxy not running',
};
}
if (isCLIProxyProcess(portProcess)) {
return { return {
id: 'cliproxy-port', id: 'cliproxy-port',
name: 'CLIProxy Port', name: 'CLIProxy Port',
status: 'ok', status: 'ok',
message: 'CLIProxy running', 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 { return {
id: 'cliproxy-port', id: 'cliproxy-port',
name: 'CLIProxy Port', name: 'CLIProxy Port',
status: 'warning', status: 'info',
message: `Occupied by ${portProcess.processName}`, message: `${CLIPROXY_DEFAULT_PORT} free`,
details: `PID ${portProcess.pid}`, details: 'Proxy not running',
fix: `Kill process: kill ${portProcess.pid}`,
}; };
} }