Sometimes, restarting Firefox causes all cookies to be lost. Closer inspection of the profile folder reveals that cookies.sqlite got renamed to cookies.sqlite.bak. A new cookies.sqlite.bak-rebuild file is present, but without any database rows.
When the problematic situation is observed, Firefox is still active and operates normally. I don't recall seeing special messages in the global browser console or standard error.
- Obviously I would expect cookies.sqlite not to get corrupted, and not observe the cookies.sqlite.bak file.
- If cookies.sqlite becomes corrupt, Firefox should try its best to recover it. For example, by writing all in-memory cookies to cookies.sqlite.
I have no reliable steps to reproduce. 11 days ago I started Firefox with special debug options, and today I finally detected the problematic event. To debug, start Firefox with:
MOZ_LOG=cookie:3 MOZ_LOG_FILE=/tmp/moz-cookies/cookies firefox
In cookies.moz_log, the following messages were visible around the time the cookies.sqlite file got renamed (see attachment for full context):
DBListenerErrorHandler::HandleError(): Error 19 occurred while performing operation 'INSERT' with message 'UNIQUE constraint failed: moz_cookies.name, moz_cookies.host, moz_cookies.path, moz_cookies.originAttributes'; rebuilding database.
HandleDBClosed(): DBState 0x7f33886ac100 encountered error rebuilding db; move to 'cookies.sqlite.bak-rebuild' gave rv 0x0
My Firefox profile is several years old, probably from 2011 or 2013.
The above issue was reproduced with Firefox 70.0.1 on Arch Linux.
I noticed the problem for the first time at 2019-08-10, at that time I was running either Firefox 67.0.4-1 or Firefox 68.0.1-2. Not sure if relevant, but the laptop was not properly shutdown prior to that event while Firefox was still running (system sleep, failure to resume -> hard shutdown). I rarely restart my browser, it may take several weeks before I do so.
In total I have noticed the problem five times:
2019-08-10 Firefox 67.0.4-1 or Firefox 68.0.1-2
2019-09-07 Firefox 68.0.1-2
2019-10-11 Firefox 69.0-1
2019-11-11 Firefox 70.0.1-1
2019-12-04 Firefox 70.0.1-3
If it is relevant, there appears to be a difference between the cookies.sqlite database scheme of my cookies.sqlite and one from a fresh Firefox profile (both using Firefox 71.0-1):
--- my old Firefox profile/cookies.sqlite
+++ a fresh Firefox profile/cookies.sqlite
@@ -1,3 +1,3 @@
-CREATE TABLE IF NOT EXISTS "moz_cookies" (
+CREATE TABLE moz_cookies (
id INTEGER PRIMARY KEY,
@@ -13,6 +13,6 @@
inBrowserElement INTEGER DEFAULT 0,
- sameSite INTEGER,
- rawSameSite INTEGER,
+ sameSite INTEGER DEFAULT 0,
+ rawSameSite INTEGER DEFAULT 0,
CONSTRAINT moz_uniqueid UNIQUE (name, host, path, originAttributes)
In my cookies.sqlite, about 60% of all cookies have NULL sameSite and rawSite fields.