Saturday, March 10, 2012

Recovering from repeated crash at Firefox (11 Beta 7) start-up

Quick Solution
 
Delete
  • session.js
  • sessionstore.bak
  • files inside sessions folder
from inside your Firefox profile directory. Follow this page to find out where you profile directory is located.

How I found what caused the crash
 
After quite few "unresponsive script" error inside Firebug 1.9.1 (mostly on LifeHacker.com and Boston.com) and repeatedly selecting "Stop Script" with no apparent benefit, I chose to kill Firefox from Windows Task Manager [1]. For those who don't know that it is - try pressing "CTRL+Shift+Esc" on your keyboard or just right-click on your task-bar and select "Start Task Manager". It looks like this:


I didn't realize the fun is just about to begin. To my surprise, upon the next restart Firefox started as usual and but quickly crashed. It kept happening much like flashing the Firefox's main window for a second or two and boom, it crashed! This behavior was already a good indication that it might be caused by a corrupted file, most probably a SQLite [2] database and this must have happened due to my killing Firefox forcefully using the Windows Task Manager. So, I started to digging around for a resolution.

First, I tried to start Firefox in "Safe Mode" with all add-ons disabled as suggested here [3] with "-safe-mode" flag. It didn't work! From my all previous experience, Firefox's safe-mode always seemed the best way to solve crash related problems, buggy extensions and add-ons. But, in this case it kept crashing even in safe-mode.

Then, I tried to open Firefox in "Private Browsing" mode with the "-private" flag. On Windows 7 (I guess on Vista too), this can be done with right-clicking the Firefox task-bar icon and selecting "Enter Private Browsing". Interestingly, Firefox was able to start in this so-called incognito mode! This was another strong hint that some files must be corrupted in my "Firefox Profile Folder" [4].

To try the theory, I closed all running instances of Firefox and I renamed Firefox's "profiles.ini" [5] to "profiles.ini.bak" to force Firefox into creating a fresh new profile. I started Firefox and it successfully created a new profile in my "%APPDATA%\Mozilla\Firefox" directory. The new profile directory was named "an9pz0cj.default".  By the way, if you are like me and you love your Firefox's plethora of customized settings and very longs list (77 in my case) of plugins only to profoundly avoid reinstalling them, don't forget to regularly backup your profile directory. My default previous profile directory was called "yn0z15ze.default" and I backed it up in a RAR archive.  After generating a fresh profile, which also generated a new profiles.ini, I copied all files (not folders, I decided to try them in the second iteration) from "an9pz0cj.default" and pasted them in "yn0z15ze.default". Windows 7's copy and paste is great. It kept showing me all the conflicts due to size, date-time of source and destination files. I kept the list of the files where the file-size was different. In my case, the list looked like the following:
  • cert8.db - SSL certificates are stored here.
  • chromeappsstore.sqlite -- HTML5 local data store.
  • content-perfs.sqlite -- Individual settings for pages.
  • permissions.sqlite -- Permission database for cookies, pop-up blocking, image loading and add-ons installation.
  • search.sqlite -- Information about search plugins
  • sessionstore.bak -- saved sessions.
  • sessionstore.js -- saved previous session
  • signons.sqlite -- Encrypted saved passwords
  • TestPilot.log --  Log file.
  • webappsstore.sqlite -- DOM local storage.
I Google'd up on the name of the files and got a rough idea of what they are meant for and how they are used inside Firefox. So, at this point I my preferred profile "yn0z15ze" is working but with some default files which means I must have lost some data, may be some customizations too as the list contains cert8.db, search.sqlite and signons.sqlite etc.

Now comes the final part - I have to test each of the files above one by one and figure out which one was causing the crash. As you may have gotten the idea already - I love my Firefox and my customizations. So, I wanted to make sure that I lose minimum amount of data due to the crash.

So, I renamed my previously moved "profiles.ini.bak" to "profiles.ini". By the way, profile.ini looks like below:
[General]
StartWithLastProfile=1

[Profile0]
Name=default
IsRelative=1
Path=Profiles/an9pz0cj.default
Default=1
So, I could have just replaced "an9pz0cj" with "yn0z15ze" and saved profile.ini to achieve switching between profiles. Anyways, I did that anyhow and started copying files as shown on the bulletted list above from  "yn0z15ze" RAR archive to now running "yn0z15ze" with some fresh files of "an9pz0cj". I kept restarting Firefox each time to check if Firefox is crashing. After a few iterations of stopping Firefox, copying fresh files into "yn0z15ze" and restarting, I stopped at "sessionstore.js". I copied this file and Firefox crashed!

Wow, so now I know which file was causing my Firefox to crash! Also, now that I know this file only contains a list of my tabs which I was browsing before the very initial task-manager kill, I can safely disregard this file now ;). Phew, so the case is solved. If you happen to come across a situation like mine, try deleting the "session.js" and/or "sessionstore.bak" and/or files inside "sessions" folder. It's weird that even in Firefox's safe-mode the problem managed to persist. Time for a bug report I guess :). Hope you find it useful.

[1] http://en.wikipedia.org/wiki/Windows_Task_Manager
[2] http://en.wikipedia.org/wiki/Sqlite
[3] http://kb.mozillazine.org/Safe_Mode
[4] http://kb.mozillazine.org/Profile_folder_-_Firefox
[5] http://kb.mozillazine.org/Profiles.ini_file