fix(bidi): force restart on close conflict or orphan session recovery
This commit is contained in:
@@ -366,15 +366,24 @@ async function ensureBridge(
|
||||
ctx?: any,
|
||||
): Promise<void> {
|
||||
if (await bridgeAlive()) return;
|
||||
if (!(await isPortOpen(9222))) {
|
||||
|
||||
if (onConflict === "close" || !(await isPortOpen(9222))) {
|
||||
await startFirefox(profile, onConflict, ctx);
|
||||
} else {
|
||||
log("Firefox già attivo su 9222: avvio solo il bridge");
|
||||
}
|
||||
|
||||
await startBridgeProcess();
|
||||
if (await waitBridgeReady()) return;
|
||||
if (await waitBridgeReady(8_000)) return;
|
||||
|
||||
// Se fallisce e non è stato fatto un restart pulito, proviamo a sbloccare la sessione orfana
|
||||
log("Bridge non pronto, tentativo recupero sessione orfana riavviando Firefox...");
|
||||
await startFirefox(profile, "close", ctx);
|
||||
await startBridgeProcess();
|
||||
if (await waitBridgeReady(15_000)) return;
|
||||
|
||||
throw new Error(
|
||||
`Bridge BiDi non stabile per ${BRIDGE_STABLE_MS}ms. Nessun riavvio automatico di Firefox eseguito. ` +
|
||||
`Bridge BiDi non stabile per ${BRIDGE_STABLE_MS}ms. ` +
|
||||
`Verifica ${BRIDGE_LOG} e lo stato della porta 9222.`,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user