Open Bug 491853 Opened 15 years ago Updated 2 years ago

Wrong windows may be restored upon restarting browser (Opened/Closed windows swap)

Categories

(Firefox :: Session Restore, defect)

x86
Windows XP
defect

Tracking

()

People

(Reporter: morac, Unassigned)

References

Details

Because of the way SessionStore's closed window list is used, namely as a combination of windows closed at shutdown and windows closed during normal operation, closed windows can end up being opened and/or open windows can end up being listed as a closed on a browser restart.

This is the simplest way to trigger this issue:
1. Set Firefox to display windows and tabs from last time.
2. Open 2 windows with 1 tab each going to a different URL. 
3. Open the Error console and type the following on 1 line:
4. var win =
Components.classes["@mozilla.org/browser/sessionstore;1"].getService(Components.interfaces.nsISessionStore).undoCloseWindow(0);
win.close();
5. Closed the error console and then close the open browser window to shutdown Firefox.
6. Start Firefox again and you'll see that the closed window and open window
have swapped.

Repeating steps 4 through 6 will cause the closed and opened windows to continuously swap. If more than one window is closed, then entering #4 above multiple times will cause all closed windows to display and all open windows to be closed.
So is it safe to assume you forgot to add step 2.5 where you close one of the windows?
Keeping with my assumption, I haven't been able to quite reproduce. I instead see both windows being opened when I restart, not seeing them swapped. My guess here is that the window is being opened & closed so quickly it's not registering correctly (not much we can do about that).

Try using this command in the error console instead of yours. It'll dump the browser state that session store has to the error console before, between, & after your steps. Take a look at the output and let me know if there's anything funky happening. (you might want to try simple pages that won't add a lot of cookies & such because the output can be pretty ugly)

var ls = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);
var ss = Components.classes["@mozilla.org/browser/sessionstore;1"].getService(Components.interfaces.nsISessionStore);
ls.logStringMessage(ss.getBrowserState());
var win = ss.undoCloseWindow(0);
ls.logStringMessage(ss.getBrowserState());
win.close();
ls.logStringMessage(ss.getBrowserState());
You are correct in that I missed step 2.5

The output after step 4 actually looks fine.  It doesn't get corrupted until after I closed the final browser window (step 5):

Here's the data I get from the command above with http://en-us.www.mozilla.com/en-US/firefox/central/ in the opened window and http://www.google.com in the closed window

{"windows":[{"tabs":[{"entries":[{"url":"http://en-us.www.mozilla.com/en-US/firefox/central/","title":"Getting Started with Firefox","ID":477983781,"scroll":"0,0"}],"index":1,"attributes":{"image":"http://en-us.www.mozilla.com/favicon.ico"},"_formDataSaved":true}],"selected":1,"_closedTabs":[],"_hosts":{"www.mozilla.com":true,"mozilla.com":true,"com":true,"en-us.www.mozilla.com":true},"width":1045,"height":994,"screenX":115,"screenY":0,"sizemode":"normal","cookies":[{"host":".mozilla.com","value":"%5B%5BB%5D%5D","path":"/","name":"s_sq"},{"host":".mozilla.com","value":"true","path":"/","name":"s_cc"},{"host":".mozilla.com","value":"183859642","path":"/","name":"__utmc"}]}],"selectedWindow":1,"_closedWindows":[{"tabs":[{"entries":[{"url":"http://www.google.com/","title":"Google","ID":0,"formdata":{"#csi":"1","/HTML/BODY/CENTER/FORM[@name='f']/TABLE/TBODY/TR/TD[2]/INPUT[@name='q']":"sddsdsdsdsds"},"scroll":"0,0"}],"index":1,"attributes":{"image":"http://www.google.com/favicon.ico"},"_formDataSaved":true}],"selected":1,"_closedTabs":[],"_hosts":{"google.com":true,"com":true,"www.google.com":true},"width":1045,"height":994,"screenX":137,"screenY":0,"sizemode":"normal","title":"Google"}]}
 ----------
{"windows":[{"tabs":[{"entries":[{"url":"http://en-us.www.mozilla.com/en-US/firefox/central/","title":"Getting Started with Firefox","ID":477983781,"scroll":"0,0"}],"index":1,"attributes":{"image":"http://en-us.www.mozilla.com/favicon.ico"},"_formDataSaved":true}],"selected":1,"_closedTabs":[],"_hosts":{"www.mozilla.com":true,"mozilla.com":true,"com":true,"en-us.www.mozilla.com":true},"width":1045,"height":994,"screenX":115,"screenY":0,"sizemode":"normal","cookies":[{"host":".mozilla.com","value":"%5B%5BB%5D%5D","path":"/","name":"s_sq"},{"host":".mozilla.com","value":"true","path":"/","name":"s_cc"},{"host":".mozilla.com","value":"183859642","path":"/","name":"__utmc"}]},{"tabs":[{"entries":[{"url":"http://www.google.com/","title":"Google","ID":0,"formdata":{"#csi":"1","/HTML/BODY/CENTER/FORM[@name='f']/TABLE/TBODY/TR/TD[2]/INPUT[@name='q']":"sddsdsdsdsds"},"scroll":"0,0"}],"index":1,"attributes":{"image":"http://www.google.com/favicon.ico"},"_formDataSaved":true}],"selected":1,"_closedTabs":[],"_hosts":{"google.com":true,"com":true,"www.google.com":true},"width":1045,"height":994,"screenX":137,"screenY":0,"sizemode":"normal","title":"Google"}],"selectedWindow":1,"_closedWindows":[]}
 ----------
{"windows":[{"tabs":[{"entries":[{"url":"http://en-us.www.mozilla.com/en-US/firefox/central/","title":"Getting Started with Firefox","ID":477983781,"scroll":"0,0"}],"index":1,"attributes":{"image":"http://en-us.www.mozilla.com/favicon.ico"},"_formDataSaved":true}],"selected":1,"_closedTabs":[],"_hosts":{"www.mozilla.com":true,"mozilla.com":true,"com":true,"en-us.www.mozilla.com":true},"width":1045,"height":994,"screenX":115,"screenY":0,"sizemode":"normal","cookies":[{"host":".mozilla.com","value":"%5B%5BB%5D%5D","path":"/","name":"s_sq"},{"host":".mozilla.com","value":"true","path":"/","name":"s_cc"},{"host":".mozilla.com","value":"183859642","path":"/","name":"__utmc"}]},{"tabs":[{"entries":[{"url":"http://www.google.com/","title":"Google","ID":0,"formdata":{"#csi":"1","/HTML/BODY/CENTER/FORM[@name='f']/TABLE/TBODY/TR/TD[2]/INPUT[@name='q']":"sddsdsdsdsds"},"scroll":"0,0"}],"index":1,"attributes":{"image":"http://www.google.com/favicon.ico"},"_formDataSaved":true}],"selected":1,"_closedTabs":[],"_hosts":{"google.com":true,"com":true,"www.google.com":true},"width":1045,"height":994,"screenX":137,"screenY":0,"sizemode":"normal","title":"Google"}],"selectedWindow":1,"_closedWindows":[]}


From the dump above it looks like both windows are still opened, even though that's not true (one is closed). 

At this point the data in sessionstore.js matches what is dumped out above, but after I closed the opened window (ie exit Firefox), sessionstore.js looks like this:

({"windows":[{"tabs":[{"entries":[{"url":"http://www.google.com/","title":"Google","ID":0,"formdata":{"#csi":"1","/HTML/BODY/CENTER/FORM[@name='f']/TABLE/TBODY/TR/TD[2]/INPUT[@name='q']":"sddsdsdsdsds"},"scroll":"0,0"}],"index":1,"attributes":{"image":"http://www.google.com/favicon.ico"},"_formDataSaved":true}],"selected":1,"_closedTabs":[],"_hosts":{"google.com":true,"com":true,"www.google.com":true},"width":1045,"height":994,"screenX":137,"screenY":0,"sizemode":"normal","title":"Google"}],"selectedWindow":0,"_closedWindows":[{"tabs":[{"entries":[{"url":"http://en-us.www.mozilla.com/en-US/firefox/central/","title":"Getting Started with Firefox","ID":477983781,"scroll":"0,0"}],"index":1,"attributes":{"image":"http://en-us.www.mozilla.com/favicon.ico"},"_formDataSaved":true}],"selected":1,"_closedTabs":[],"_hosts":{"www.mozilla.com":true,"mozilla.com":true,"com":true,"en-us.www.mozilla.com":true},"width":1045,"height":994,"screenX":115,"screenY":0,"sizemode":"normal","cookies":[{"host":".mozilla.com","value":"%5B%5BB%5D%5D","path":"/","name":"s_sq"},{"host":".mozilla.com","value":"true","path":"/","name":"s_cc"},{"host":".mozilla.com","value":"183859642","path":"/","name":"__utmc"}],"title":"Getting Started with Firefox"}],"session":{"state":"stopped","lastUpdate":1241723796480}})


As you can see Google is now in the active (open) window position and the Start page is now in the _closedWindow[] array.

I think the problem occurs because SessionStore's internal state gets out of whack with the actual current browser state.  When the current window is closed (Firefox shuts down), the "open" window correctly goes into the closed window list, but that leaves the "closed" window in the open window list.  So when Firefox is started up, the 'closed" window is restored and the "open" window shows up in the closed list.

So if closing the window causes Firefox to shut down, then the closed and opened windows will be reversed.  Shutting down Firefox using the File->Exit command results in both windows being opened like you said you saw.
Simple steps to reproduce wrong window being restored (win7 64bit FF30.0)

1. Populate window 1 with 1 page/tab
2. populate window 2 with multiple pages/tabs
3. Close tab in window 1 to blank tab.
4. clear history.
5. Close window 2 (multiple tabs/pages)
6. Close window 1 (blank)
7. Open Firefox - Window 2 appears instead of window 1.
PS, tested again, clear history step wasn't necessary.
Firefox 31, still happening, but not always repeatable.
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.