fix(popups): reload a popup renderer after it crashes
The window survives a renderer crash, so the get*Window() getters never recreated it and the popup stayed blank until the app restarted (and a crashed suggestion overlay could still swallow clicks). On crashed, oom or abnormal-exit the ready flag is cleared and the renderer reloads, at most once per 30s so a renderer that keeps dying is not restarted in a loop.
This commit is contained in:
parent
ddd734fd30
commit
bdec40d8b7
2 changed files with 70 additions and 0 deletions
|
|
@ -120,9 +120,38 @@ function hookPopupDiagnostics(win: BrowserWindow, name: string): void {
|
|||
})
|
||||
win.webContents.on('render-process-gone', (_event, details) => {
|
||||
logger.error(`[${name}] renderer process gone: ${details.reason} (exitCode=${details.exitCode})`)
|
||||
recoverPopupRenderer(win, name, details.reason)
|
||||
})
|
||||
}
|
||||
|
||||
/** 팝업 렌더러가 죽은 뒤 다시 불러오는 최소 간격 — 곧바로 또 죽는 경우 재시작을 반복하지 않게 */
|
||||
export const POPUP_RENDERER_RELOAD_INTERVAL_MS = 30_000
|
||||
const lastPopupReloadAt = new WeakMap<BrowserWindow, number>()
|
||||
|
||||
/**
|
||||
* 창은 살아 있고 렌더러만 죽으면 get*Window() 가 창을 다시 만들지 않아, 재시작 전까지 팝업이 빈 창으로 남았다.
|
||||
* 준비 표시를 지우고(보낸 메시지는 다시 쌓인다) 렌더러를 다시 불러온다.
|
||||
*/
|
||||
export function recoverPopupRenderer(
|
||||
win: BrowserWindow,
|
||||
name: string,
|
||||
reason: string,
|
||||
now: number = Date.now(),
|
||||
): boolean {
|
||||
popupReady.delete(win)
|
||||
if (reason !== 'crashed' && reason !== 'oom' && reason !== 'abnormal-exit') return false
|
||||
if (win.isDestroyed() || win.webContents.isDestroyed()) return false
|
||||
const last = lastPopupReloadAt.get(win)
|
||||
if (last !== undefined && now - last < POPUP_RENDERER_RELOAD_INTERVAL_MS) {
|
||||
logger.warn(`[${name}] renderer crashed again within ${POPUP_RENDERER_RELOAD_INTERVAL_MS}ms — not reloading`)
|
||||
return false
|
||||
}
|
||||
lastPopupReloadAt.set(win, now)
|
||||
win.webContents.reload()
|
||||
logger.info(`[${name}] renderer reloaded after ${reason}`)
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Deliver IPC to a popup even while its renderer is still loading.
|
||||
* webContents.send before load is silently dropped, which leaves popups stuck
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
// tests/main/windows/popup-renderer-recovery.test.ts
|
||||
// 팝업 렌더러가 죽으면 다시 불러온다(창이 살아 있어 다시 만들어지지 않으므로). 연속 크래시는 반복하지 않는다.
|
||||
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import type { BrowserWindow } from 'electron'
|
||||
import {
|
||||
POPUP_RENDERER_RELOAD_INTERVAL_MS,
|
||||
recoverPopupRenderer,
|
||||
} from '../../../src/main/windows/popup-window-factory'
|
||||
|
||||
function fakeWindow(): { win: BrowserWindow; reload: ReturnType<typeof vi.fn> } {
|
||||
const reload = vi.fn()
|
||||
const win = {
|
||||
isDestroyed: () => false,
|
||||
webContents: { isDestroyed: () => false, reload },
|
||||
} as unknown as BrowserWindow
|
||||
return { win, reload }
|
||||
}
|
||||
|
||||
describe('recoverPopupRenderer', () => {
|
||||
it('크래시면 렌더러를 다시 불러온다', () => {
|
||||
const { win, reload } = fakeWindow()
|
||||
expect(recoverPopupRenderer(win, 'tip', 'crashed', 1_000)).toBe(true)
|
||||
expect(reload).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('정상 종료·강제 종료(앱 종료 중)는 다시 불러오지 않는다', () => {
|
||||
const { win, reload } = fakeWindow()
|
||||
expect(recoverPopupRenderer(win, 'tip', 'clean-exit', 1_000)).toBe(false)
|
||||
expect(recoverPopupRenderer(win, 'tip', 'killed', 1_000)).toBe(false)
|
||||
expect(reload).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('간격 안에 또 죽으면 다시 불러오지 않고, 간격이 지나면 다시 불러온다', () => {
|
||||
const { win, reload } = fakeWindow()
|
||||
recoverPopupRenderer(win, 'tip', 'oom', 1_000)
|
||||
expect(recoverPopupRenderer(win, 'tip', 'oom', 1_000 + POPUP_RENDERER_RELOAD_INTERVAL_MS - 1)).toBe(false)
|
||||
expect(recoverPopupRenderer(win, 'tip', 'oom', 1_000 + POPUP_RENDERER_RELOAD_INTERVAL_MS)).toBe(true)
|
||||
expect(reload).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue