Skip to content
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

Browser processes killed on WM_QUERYENDSESSION #3700

Open
jebihug opened this issue Aug 10, 2023 · 4 comments
Open

Browser processes killed on WM_QUERYENDSESSION #3700

jebihug opened this issue Aug 10, 2023 · 4 comments
Assignees
Labels
bug Something isn't working tracked We are tracking this work internally.

Comments

@jebihug
Copy link

jebihug commented Aug 10, 2023

My application is listening for the WM_QUERYENDSESSION message. If the user has not saved his work then a shutdown reason block is set (ShutdownBlockReasonCreate) and FALSE is returned.
When the user logoff, Windows display a screen showing applications that hang with the message defined with ShutdownBlockReasonCreate. If the user cancel the end of the Windows session because he realize that he haven't saved something, then the application is reshown but the browser processes have been killed and the application show balck screen insteed of the web page.

This is reproductible with the WebView2APISample, is you modify the WM_QUERYENDSESSION with:

case WM_QUERYENDSESSION:
{
    // yes, we can shut down
    // Register how we might be restarted
    /*RegisterApplicationRestart(L"--restore", RESTART_NO_CRASH | RESTART_NO_HANG);
    *result = TRUE;
    */
    ShutdownBlockReasonCreate(m_mainWindow, L"Block");
    *result = FALSE;
    return true;
}

Before the user query the end of session:

before

After the user canceled the end of session:

After

I think that the browser process should not be terminated before the application is realy being terminated.

If I use SetProcessShutdownParameters(0x3FF, 0); in the main application to set the shutdown priority the "highest" then the problem disappear. Is this because the application receive early the WM_QUERYENDSESSION and respond FALSE and then others processes do not receive the WM_QUERYENDSESSION ?
Is this workaround will always works ?

AB#46194890

@jebihug jebihug added the bug Something isn't working label Aug 10, 2023
@Urmeli0815
Copy link

We have a similar problem. In our app we need to use SetProcessShutdownParameters to move the shutdown of the app to the latest point possible. When another app blocks the shutdown (e. g. having Paint open with a non-saved image) the WV2-Processes get killed, then the user cancels the shutdown and our app displays a blank window.

I think it would be good if the value of SetProcessShutdownParameters could also be passed to WV2, either via API or by AdditionalBrowserArguments.

@LiangTheDev LiangTheDev added the tracked We are tracking this work internally. label Aug 25, 2023
@LiangTheDev
Copy link
Member

I think that it is WM_ENDSESSION that is killing the WebView browser processes. So, if app process stops shutdown before OS tries to shutdown WebView browser processes, WebView2 browser processes would not be killed. This would always work. On the other hand, if the app is set to be shutdown last, WebView2 browser processes could be shutdown before the app process.

I've created a tracking work item for this and see whether we can do something about and not impacting normal logoff/shutdown or WebView2 Runtime uninstall scenarios.

@andy-clapham
Copy link

This has been quiet for a while - any progress to report?
This is affecting PowerBI users who loose unsaved work on shutdown.

A corollary to Urmeli0815's suggestion would be for the webview process to always set its own priority to one earlier than default, i.e. 0x27F; would fix a lot of things :)

@LiangTheDev
Copy link
Member

At the moment the best solution would be the workaround mentioned by jebihug: the app calls SetProcessShutdownParameters(0x281, 0) so that the app process got notified before WebView2 processes. If the app doesn't have a requirement of being notified of shutdown later than default, this should work.

The work item is still active, but not a high priority work item right now. As there are a set of WebView2 processes, and within the group there are relative shutdown orders, it requires some designing for how to solve the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests

5 participants