Refactor cloudflared process management to improve port-specific termination and enhance tunnel management. Update Antigravity cloaking comments for clarity.
This commit is contained in:
@@ -360,7 +360,21 @@ export async function spawnQuickTunnel(localPort, onUrlUpdate) {
|
||||
});
|
||||
}
|
||||
|
||||
export function killCloudflared() {
|
||||
// Kill cloudflared processes whose command line targets the given port (any host).
|
||||
// Boundary check ensures :20128 doesn't match :201280 or :202128.
|
||||
function killCloudflaredByPort(port) {
|
||||
if (!port) return;
|
||||
try {
|
||||
if (IS_WINDOWS) {
|
||||
const psCmd = `Get-CimInstance Win32_Process -Filter \\"Name='cloudflared.exe'\\" | Where-Object { $_.CommandLine -match ':${port}(\\D|$)' } | ForEach-Object { Stop-Process -Id $_.ProcessId -Force }`;
|
||||
execSync(`powershell -NoProfile -Command "${psCmd}"`, { stdio: "ignore", windowsHide: true });
|
||||
} else {
|
||||
execSync(`pkill -f "cloudflared.*:${port}([^0-9]|$)" 2>/dev/null || true`, { stdio: "ignore", windowsHide: true });
|
||||
}
|
||||
} catch (e) { /* ignore */ }
|
||||
}
|
||||
|
||||
export function killCloudflared(localPort) {
|
||||
if (cloudflaredProcess) {
|
||||
try {
|
||||
cloudflaredProcess.kill();
|
||||
@@ -376,10 +390,7 @@ export function killCloudflared() {
|
||||
clearPid();
|
||||
}
|
||||
|
||||
// Kill any remaining cloudflared processes
|
||||
try {
|
||||
execSync("pkill -f cloudflared 2>/dev/null || true", { stdio: "ignore", windowsHide: true });
|
||||
} catch (e) { /* ignore */ }
|
||||
killCloudflaredByPort(localPort);
|
||||
}
|
||||
|
||||
export function isCloudflaredRunning() {
|
||||
|
||||
Reference in New Issue
Block a user