Bug 1177310 - [e10s] Stop using CPOWs on application shutdown
Alright, this will build off of the work I did in bug 1171708.

Ok, patch up for review.

can you try a test where you load a page that spins in JS and then quit the browser? I'm curious what happens.

What happens is that the windows stick around. :/

What about at quit-application? Or profile-change-teardown? Or profile-before-change?

Idea: Have TabStateFlusher expose a Promise that will resolve when all pending TabStateFlusher flushes are resolved?

How that’d work:

For every flush (window or browser), before we return the Promise to the caller, add the Promise to an Array. When the Promise is resolved, have it be removed from the Array.

Have TabStateFlusher.pendingFlushesDone return a Promise.all for that Array.

let sleeps = [];

function sleep(aMs) {
let promise = new Promise(resolve => {
setTimeout(function() {
console.log("Done sleeping for " + aMs + " ms");
let index = sleeps.indexOf(promise);
sleeps.splice(index, 1);
resolve();
}, aMs);
});
sleeps.push(promise);
return promise;
}

sleep(100);
sleep(200);
sleep(1000);
sleep(2000);
sleep(2500);
sleep(5000);

setTimeout(function() {
Promise.all(sleeps).then(() => {
console.log("All done: " + sleeps.length);
});
}, 1500);

^— This seems to suggest that my plan should technically work.

But… I can’t just close the windows. SessionStore will interpret that as the user actually having chosen to close the window. I have to flush them. :/

It’d be great if I could flush them just before or just after the XUL windows start coming down

How are windows destroyed when the application is coming down? I think I can figure that out.

Some kind of nsCloseEvent is fired inside nsGlobalWindow, and that does the job of destroying the nsXULWindow.

Solution?

  1. At quit-application-granted (which flips off the RunState), flush the windows
  2. Close the windows
  3. Wait for the flushes to complete

So this only kinda works. There is at least one test in sessionstore/test/ that intentionally never sends up an :update, so we have this dangling flush that never completes. What do we do about that?

billm seems to think it’s okay to resolve in that case, though perhaps with some kind of way of detecting “not so great” flush resolutions. Like passing a success and message to the resolve method.

Add quit-application-granted to the AsyncShutdown phase list
TabStateFlusher flush Promises should always resolve, but some resolve in better ways than others
Keep a Set of active flush Promises in the TabStateFlusher, and expose a Promise that resolves when they all resolve. Add documentation about how these should always resolve, even if the content process crashes.
Get the AsyncShutdown code in there
Figure out if we need to really resolve the flushes inside the cleanUpWindow method
At quit-application-granted, flush the windows and close immediately then wait for the flush to complete (so we can record the progress), then wait for all remaining pending flushes to complete.
Look at shutdown tests in bug 923606

Try push with talos other: https://treeherder.mozilla.org/#/jobs?repo=try&revision=e258f88bb41d
Compare: https://treeherder.mozilla.org/perf.html#/compare?originalProject=fx-team&originalRevision=17edd5432965&newProject=try&newRevision=e258f88bb41d