Closed
Bug 480466
Opened 17 years ago
Closed 17 years ago
Shutdown dispatches quit-application-granted twice
Categories
(Toolkit :: Startup and Profile System, defect)
Tracking
()
RESOLVED
FIXED
mozilla1.9.3a1
| Tracking | Status | |
|---|---|---|
| status1.9.2 | --- | beta1-fixed |
People
(Reporter: bzbarsky, Assigned: mossop)
References
Details
Attachments
(3 files)
|
9.14 KB,
text/plain
|
Details | |
|
3.11 KB,
text/plain
|
Details | |
|
6.86 KB,
patch
|
benjamin
:
review+
benjamin
:
approval1.9.2+
|
Details | Diff | Splinter Review |
1) nsCloseEvent::Run closing the last window, which calls nsAppStartup::ExitLastWindowSurvivalArea which calls nsAppStartup::Quit, which notifies observers.
2) An XBL key handler (I quit using Cmd-Q on Mac), calling some JS, calling nsAppStartup::Quit directly
It looks like nsAppStartup::Quit dispatches quit-application-granted, then tries to close windows, and if that fails (which it says is "often") it bails out and retries once the windows are closed. At that point it dispatches the notification again.
| Reporter | ||
Updated•17 years ago
|
Assignee: nobody → benjamin
Comment 1•17 years ago
|
||
bz, can I have stacks for both calls? It seems odd to me that the window-closing things happens first, *then* the Cmd-Q handler.
It's also possible/likely that we shouldn't be resetting mShuttingDown here: http://mxr.mozilla.org/mozilla-central/source/toolkit/components/startup/src/nsAppStartup.cpp#86 or we're not checking mRunning properly.
Dave, do you remember exactly how the three flags (mShuttingDown/mRunning/mAttemptingQuit) are supposed to work together? We should probably document them because every time I look at this code I have to relearn it.
| Reporter | ||
Comment 2•17 years ago
|
||
I would assume the window-closing happens second. I just listed them in the order the appeared in in the shark profile.
Stacks coming up; one sec.
| Reporter | ||
Comment 3•17 years ago
|
||
| Reporter | ||
Comment 4•17 years ago
|
||
| Assignee | ||
Comment 5•17 years ago
|
||
This is what I think is true:
mShuttingDown is used to signal that the application is attempting to shut down. It should be set to true when Quit is called and determines that shutdown is necessary, and not changed to false until we have decided that we have finally shutdown.
mRunning is set to true when the application event loop is started and set to false after the event loop is exited, so basically true while the app is open and responding to events from the OS.
mAttemptingQuit is only used on OSX. It is set to true when Quit is called and a shutdown is attempted and set to false if a window is opened. Its purpose is to flag that we should ignore the hidden window when counting how many useful windows are still open. The application automatically exits when there are no useful windows left.
Reading these back it seems likely to me that mShuttingDown and mAttemptingQuit are serving pretty much the same purpose and mShuttingDown is mostly redundant.
Comment 6•17 years ago
|
||
I'll mention that I see "quit-application-granted" twice on the Windows version of Firefox as well, but only when the File->Exit command is used to quit Firefox. If the last browser window is closed (which exits Firefox in Windows), the "quit-application-granted" is only dispatched once.
So this isn't OS X only.
See bug 483566 comment #6.
Comment 7•17 years ago
|
||
might complications related to multiple dispatch cause prefs dataloss as postulated in bug 422447 comment 7? (or other dataloss bugs)
Updated•17 years ago
|
Assignee: benjamin → dtownsend
| Assignee | ||
Comment 8•17 years ago
|
||
(In reply to comment #5)
> This is what I think is true:
Ok this was wrong. Here is what actually goes on:
mRunning is set to true when the application event loop is started and set to false after the event loop is exited, so basically true while the app is open and responding to events from the OS.
mAttemptingQuit is set to true when Quit has been called and the application is attempting to shutdown. This shutdown is asynchronous, we must tell all windows to close and then return from Quit waiting for them to do so. mAttemptingQuit remains true until the attempt to shutdown is abandoned by a new window opening.
mShuttingDown is set to true while we are in the Quit method. If we have to exit from Quit to wait for windows to close it gets set back to false. If all Quit finds that all windows are closed then it dispatches the shutdown event and mShuttingDown remains true.
The only way to stop quit-application-granted being dispatched twice in the same session (and retain sanity) would be to move it to after the point where all windows have closed. This is the same point that we dispatch quit-application already.
The alternative would be to dispatch it as it is now when we attempt to close windows, and assuming shutdown is never aborted never dispatch it again. However in that scenario I think it would be sensible to dispatch an event when shutdown is aborted and basically say that quit-application-granted might happen again after that.
Comment 9•17 years ago
|
||
How can shutdown be aborted after the quit-application-granted notification goes out? That notification is only supposed to be sent when all quit-application-requested observers have agreed to allow shutdown to occur.
Basically it's supposed to be beyond the point of not return at that point in the shutdown process. If this isn't the case and shutdown is somehow aborted after a quit-application-granted notification is issued, a number of add-ons and components will get into a bad state.
| Assignee | ||
Comment 10•17 years ago
|
||
(In reply to comment #9)
> How can shutdown be aborted after the quit-application-granted notification
> goes out? That notification is only supposed to be sent when all
> quit-application-requested observers have agreed to allow shutdown to occur.
Currently opening a new window will abort the shutdown process. However we've decided that once we reach this point only modal windows may be opened which will pause the shutdown process until they are closed at which point it will resume again. This change means we should be ok to leave the notification where it is and still only dispatch it once.
| Assignee | ||
Comment 11•17 years ago
|
||
Per the discussion this makes quit-application-granted dispatched once. After that no non-modal windows can open and the notification will not be sent again. Since we never cancel the shutdown now we can remove the fix implemented in bug 449308.
Attachment #395077 -
Flags: review?(benjamin)
| Assignee | ||
Updated•17 years ago
|
Status: NEW → ASSIGNED
Comment 12•17 years ago
|
||
Comment on attachment 395077 [details] [diff] [review]
patch rev 1
>diff --git a/toolkit/components/startup/src/nsAppStartup.cpp b/toolkit/components/startup/src/nsAppStartup.cpp
>@@ -461,16 +415,20 @@ nsAppStartup::CreateChromeWindow2(nsIWeb
> PRBool *aCancel,
> nsIWebBrowserChrome **_retval)
> {
> NS_ENSURE_ARG_POINTER(aCancel);
> NS_ENSURE_ARG_POINTER(_retval);
> *aCancel = PR_FALSE;
> *_retval = 0;
>
>+ // Non-modal windows cannot be opened if we are attempting to quit
>+ if (mAttemptingQuit && (aChromeFlags & nsIWebBrowserChrome::CHROME_MODAL) == 0)
>+ return NS_ERROR_FAILURE;
I so do very much want a NS_ERROR_UNAVAILABLE_SHUTTING_DOWN error code... would you like to add one to nsError.h?
Attachment #395077 -
Flags: review?(benjamin) → review+
| Assignee | ||
Comment 13•17 years ago
|
||
(In reply to comment #12)
> (From update of attachment 395077 [details] [diff] [review])
> >diff --git a/toolkit/components/startup/src/nsAppStartup.cpp b/toolkit/components/startup/src/nsAppStartup.cpp
>
> >@@ -461,16 +415,20 @@ nsAppStartup::CreateChromeWindow2(nsIWeb
> > PRBool *aCancel,
> > nsIWebBrowserChrome **_retval)
> > {
> > NS_ENSURE_ARG_POINTER(aCancel);
> > NS_ENSURE_ARG_POINTER(_retval);
> > *aCancel = PR_FALSE;
> > *_retval = 0;
> >
> >+ // Non-modal windows cannot be opened if we are attempting to quit
> >+ if (mAttemptingQuit && (aChromeFlags & nsIWebBrowserChrome::CHROME_MODAL) == 0)
> >+ return NS_ERROR_FAILURE;
>
> I so do very much want a NS_ERROR_UNAVAILABLE_SHUTTING_DOWN error code... would
> you like to add one to nsError.h?
I just discovered that there is already a NS_ERROR_ILLEGAL_DURING_SHUTDOWN, shall I just use that or do you want me to create another?
Comment 14•17 years ago
|
||
illegal_during_shutdown sounds perfect
| Assignee | ||
Comment 15•17 years ago
|
||
Landed with that change: http://hg.mozilla.org/mozilla-central/rev/f055a62bf0b0
Status: ASSIGNED → RESOLVED
Closed: 17 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla1.9.3a1
| Assignee | ||
Updated•17 years ago
|
Whiteboard: [needs baking]
| Assignee | ||
Comment 16•17 years ago
|
||
Comment on attachment 395077 [details] [diff] [review]
patch rev 1
Doesn't seem to be any fallout from this, we should take it on the branch.
Attachment #395077 -
Flags: approval1.9.2?
| Assignee | ||
Updated•17 years ago
|
Whiteboard: [needs baking]
Updated•17 years ago
|
Attachment #395077 -
Flags: approval1.9.2? → approval1.9.2+
| Assignee | ||
Comment 17•17 years ago
|
||
Landed on the branch: http://hg.mozilla.org/releases/mozilla-1.9.2/rev/aa98fc7c4a81
status1.9.2:
--- → beta1-fixed
You need to log in
before you can comment on or make changes to this bug.
Description
•