New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(pre-req): several fixes to the current hidden window launching process - INS-3319 #7174
Conversation
Please clean up commits in this PR and address both detection and recovery. |
c511733
to
50b27b2
Compare
…est is always timeout
// as the hidden window is restarted, it should not show "Timeout: Hidden browser window is not responding" | ||
await page.getByText('Timeout: Pre-request script took too long').click(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔
If i'm not mistaken this PR doesn't yet detect a a unresponsive or closed window it just tries to open the same window on every run and the promise will hang if the hidden window isn't up. Either way its important to make it very clear here since it we can't afford for this mechanism to be buggy. |
Thanks for heads up, I've just added the mechanism to restart the stuck hidden window. |
I would say that it should still be an advance as in the current implementation the hidden window seems never up. :( |
I would like to share 2 videos to help understand how does current window restarting mechanism work: In this one, the hidden window is not started at beginning, it is started when In this one, one infinite loop script is enabled. In the first sending, it hangs. And cancel the first one, disable infinite loop and re-trigger |
9596351
to
1c53738
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to help move this PR forward and add value faster. I took the liberty of removing the new code paths and focused this PR in to only fixing the start hidden window bug. Lets address the retry mechanism in its own PR since it is not a trivial UX or implementation. I have left the commits in detailing the approach to syncing a busy flag in main file scoped variable. So we can check the trade-offs against other detection and retry mechanisms.
7577e51
to
f8c6d2a
Compare
stopHiddenBrowserWindow(); | ||
}); | ||
} | ||
export async function createHiddenBrowserWindow() { | ||
const hiddenBrowserWindow = new BrowserWindow({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we check the browsers windows map outside of this function we no longer need to detect it being open and restart it. Since we should aim to trust the state of this map otherwise there is no benefit to keeping a record of its state in the map.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me try to clarify it. The state of window and the state of execution are 2 different states.
The windows map: means the hidden window is up or down.
The busy state: means if the hidden window is busy.
So, the hidden window is up != the hidden window is busy.
If the busy state is unknown, the mechanism must restart the window every time (to avoid it hangs), which seems not a good option for performance.
I can give more detailed elaboration of these 2 states if you would like to.
const mainWindow = browserWindows.get('Insomnia') ?? createWindow(); | ||
if (!browserWindows.get('HiddenBrowserWindow')) { | ||
createHiddenBrowserWindow(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it helps to keep createWindow and createHiddenWindow signatures and behaviour aligned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool
f8c6d2a
to
8010fcf
Compare
Really thankful for the review, probably some points should be clarified to make sure that we are on the same page:
Some tests are also failed after force-pushing, so changes are stored. Lets follow the review process in most of repos by adding comments instead of modifying them. |
@@ -57,5 +60,6 @@ test('handle hidden browser window getting closed', async ({ app, page }) => { | |||
const hiddenWindow = windows[1]; | |||
hiddenWindow.close(); | |||
await page.getByRole('button', { name: 'Send' }).click(); | |||
await page.getByText('Timeout: Hidden browser window is not responding').click(); | |||
// as the hidden window is restarted, it should not show "Timeout: Hidden browser window is not responding" | |||
await page.getByText('Timeout: Pre-request script took too long').click(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await page.getByText('Timeout: Pre-request script took too long').click(); | |
await page.getByText('Timeout: An error occurred while running a pre-request script please restart Insomnia').click(); |
ipcMain.removeHandler('renderer-listener-ready'); | ||
const hiddenWinListenerReady = new Promise<void>(resolve => { | ||
ipcMain.handleOnce('renderer-listener-ready', () => { | ||
console.log('[main] hidden window listener is ready'); | ||
resolve(); | ||
}); | ||
}); | ||
await hiddenWinListenerReady; | ||
|
||
ipcMain.removeHandler('hidden-window-received-port'); | ||
const hiddenWinPortReady = new Promise<void>(resolve => { | ||
ipcMain.handleOnce('hidden-window-received-port', () => { | ||
console.log('[main] hidden window has received port'); | ||
resolve(); | ||
}); | ||
}); | ||
|
||
const { port1, port2 } = new MessageChannelMain(); | ||
hiddenBrowserWindow.webContents.postMessage('renderer-listener', null, [port1]); | ||
await hiddenWinPortReady; | ||
|
||
ipcMain.removeHandler('main-window-script-port-ready'); | ||
const mainWinPortReady = new Promise<void>(resolve => { | ||
ipcMain.handleOnce('main-window-script-port-ready', () => { | ||
console.log('[main] main window has received hidden window port'); | ||
resolve(); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see value in this. Can you explain why its required in this bug fix PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Value add: this is a defensive way to show a console log allowing a specific sync error to be deduced from app logs.
Suspect IssuesThis pull request was deployed and Sentry observed the following issues:
Did you find this useful? React with a 👍 or 👎 |
Please review this PR (#7173) firstly as current one is based on it
Changes:
How to test
Try to close the hidden window or make it crash and send a request.