fix(desktop): wait for backend exit before reloading on connection-config apply

The apply handler sent SIGTERM then fired a 150 ms setTimeout to reload
the renderer. If the backend took longer to shut down the port was still
bound when startHermes() ran after reload, causing an "address already
in use" failure.

Capture the process reference before resetHermesConnection() nulls it,
then await the actual exit event. A 5 s SIGKILL fallback ensures the
wait never hangs if the backend ignores SIGTERM.
This commit is contained in:
AhmetArif0 2026-06-03 18:12:37 +03:00 committed by Teknium
parent fef04a197e
commit 6feb40e702

View file

@ -4076,9 +4076,26 @@ ipcMain.handle('hermes:connection-config:save', async (_event, payload) => {
ipcMain.handle('hermes:connection-config:apply', async (_event, payload) => {
const config = coerceDesktopConnectionConfig(payload)
writeDesktopConnectionConfig(config)
resetHermesConnection()
setTimeout(() => mainWindow?.reload(), 150)
// Capture the reference before resetHermesConnection() nulls hermesProcess,
// so we can wait for actual exit rather than assuming a fixed delay is enough.
const dying = hermesProcess && !hermesProcess.killed ? hermesProcess : null
resetHermesConnection()
if (dying) {
await new Promise(resolve => {
const timer = setTimeout(() => {
try { dying.kill('SIGKILL') } catch {}
resolve()
}, 5000)
dying.once('exit', () => {
clearTimeout(timer)
resolve()
})
})
}
mainWindow?.reload()
return sanitizeDesktopConnectionConfig(config)
})