Closed Bug 1897303 Opened 1 year ago Closed 10 months ago

Folder cache entries not removed on account removal

Categories

(Thunderbird :: General, defect)

defect

Tracking

(Not tracked)

RESOLVED FIXED
140 Branch

People

(Reporter: leftmostcat, Assigned: babolivier)

References

(Blocks 1 open bug)

Details

Attachments

(1 file, 2 obsolete files)

When deleting an account, the entries relating to its folders are not removed from folderCache.json. For EWS work, this causes properties representing local state to be incorrectly retained when deleting and recreating an account.

We would expect that https://searchfox.org/comm-central/source/mailnews/base/src/nsMsgDBFolder.cpp#3279 would address this, but that doesn't seem to be happening.

See Also: → 1897313

Hello Sean,

Is there something QA can manually do in order to reproduce this issue?

If not, could you please update the affected version in Tracking Flags(if that applies)?

Thank you in advance!

Flags: needinfo?(leftmostcat)

(In reply to Sean Burke [:leftmostcat] from comment #0)

When deleting an account, the entries relating to its folders are not removed from folderCache.json. For EWS work, this causes properties representing local state to be incorrectly retained when deleting and recreating an account.

But doesn't impact non-EWS users?

Flags: needinfo?(leftmostcat)

(In reply to Wayne Mery (:wsmwk) from comment #2)

(In reply to Sean Burke [:leftmostcat] from comment #0)

When deleting an account, the entries relating to its folders are not removed from folderCache.json. For EWS work, this causes properties representing local state to be incorrectly retained when deleting and recreating an account.

But doesn't impact non-EWS users?

I've just taken a look at this. Folder entries aren't removed from the folder cache regardless of the account type (I can see folders from an IMAP account I've deleted in my test profile's folder cache). For EWS, this creates a bigger problem than other protocols, because we use the folder properties (which are copied to the folder cache) to store a token allowing us to tell the server which changes we've seen to the message list for a given folder, so we don't bother syncing changes we've already seen. As a result, removing an EWS account then adding it again leaves all folders empty (because we think we've already seen all the messages that are available).

This is not as big an issue with other protocols, because they use a different logic to figure out what to sync. However, it might affect users in a less harmful way by retaining e.g. flags, properties, etc that might have been set on one (now deleted) account and applying them to another (new) one.

(In reply to Sean Burke [:leftmostcat] from comment #0)

When deleting an account, the entries relating to its folders are not removed from folderCache.json. For EWS work, this causes properties representing local state to be incorrectly retained when deleting and recreating an account.

We would expect that https://searchfox.org/comm-central/source/mailnews/base/src/nsMsgDBFolder.cpp#3279 would address this, but that doesn't seem to be happening.

This searchfox link points to nsMsgDBFolder::DeleteStorage(), but it doesn't look like this is called at all during the account deletion process. Nor is nsMsgDBFolder::RecursiveDelete() which performs the actual removal from the cache.

We already perform some actions on individual folders when deleting an account: https://searchfox.org/comm-central/rev/1016048a635bd062b826bfe767c86acaeadd004a/mailnews/base/src/nsMsgAccountManager.cpp#562-570
So we might be able to update that block to also remove each folder from the cache.

Assignee: nobody → brendan
Status: NEW → ASSIGNED
Target Milestone: --- → 139 Branch

Actually I just remembered there's a test that needs fixing before this can land.

Pushed by heather@thunderbird.net:
https://hg.mozilla.org/comm-central/rev/9b970f296967
Remove folders from the folder cache on account removal. r=heather

Status: ASSIGNED → RESOLVED
Closed: 11 months ago
Resolution: --- → FIXED

This is perma failing (crashing) comm/mail/test/browser/account/browser_accountTelemetry.js
https://treeherder.mozilla.org/jobs?repo=comm-central&selectedTaskRun=GXg5MEpXTCeIL7w7XhpKxg.0

#0  nsMsgAccountManager::RemoveFolderFromCache (this=this@entry=0x7fffc60ddec0, aFolder=0x7fffc7c48340)
    at /home/magnus/Code/tb/mozilla/comm/mailnews/base/src/nsMsgAccountManager.cpp:640
#1  0x00007fffee1e0bbc in nsMsgAccountManager::RemoveIncomingServer (this=0x7fffc60ddec0, aServer=0x7fffb22f9c40, aRemoveFiles=false)
    at /home/magnus/Code/tb/mozilla/comm/mailnews/base/src/nsMsgAccountManager.cpp:583
#2  0x00007fffee1e1158 in nsMsgAccountManager::RemoveAccount (this=0x7fffc60ddec0, aAccount=0x7fffb5056ab0, aRemoveFiles=false)
    at /home/magnus/Code/tb/mozilla/comm/mailnews/base/src/nsMsgAccountManager.cpp:746
#3  0x00007fffe947d106 in NS_InvokeByIndex () at /home/magnus/Code/tb/mozilla/xpcom/reflect/xptcall/md/unix/xptcinvoke_asm_x86_64_unix.S:101

I had understood MOZ_TRY as basically doing NS_ENSURE_SUCCESS. If causing crashes for things like this we should not be using it.

Flags: needinfo?(brendan)

This is also causing the perma comm/mail/services/sync/test/unit/test_server_tracker.js failure

Regressions: 1961362

(In reply to Magnus Melin [:mkmelin] from comment #8)

This is perma failing (crashing) comm/mail/test/browser/account/browser_accountTelemetry.js
https://treeherder.mozilla.org/jobs?repo=comm-central&selectedTaskRun=GXg5MEpXTCeIL7w7XhpKxg.0

#0  nsMsgAccountManager::RemoveFolderFromCache (this=this@entry=0x7fffc60ddec0, aFolder=0x7fffc7c48340)
    at /home/magnus/Code/tb/mozilla/comm/mailnews/base/src/nsMsgAccountManager.cpp:640
#1  0x00007fffee1e0bbc in nsMsgAccountManager::RemoveIncomingServer (this=0x7fffc60ddec0, aServer=0x7fffb22f9c40, aRemoveFiles=false)
    at /home/magnus/Code/tb/mozilla/comm/mailnews/base/src/nsMsgAccountManager.cpp:583
#2  0x00007fffee1e1158 in nsMsgAccountManager::RemoveAccount (this=0x7fffc60ddec0, aAccount=0x7fffb5056ab0, aRemoveFiles=false)
    at /home/magnus/Code/tb/mozilla/comm/mailnews/base/src/nsMsgAccountManager.cpp:746
#3  0x00007fffe947d106 in NS_InvokeByIndex () at /home/magnus/Code/tb/mozilla/xpcom/reflect/xptcall/md/unix/xptcinvoke_asm_x86_64_unix.S:101

I had understood MOZ_TRY as basically doing NS_ENSURE_SUCCESS. If causing crashes for things like this we should not be using it.

Ugh, sorry, I completely missed this one.

MOZ_TRY does return an error like NS_ENSURE_SUCCESS. Looking at logs and reproducing locally, it seems like folderPath is null here: https://searchfox.org/comm-central/rev/898aba590fb8b29599ec1669cda1691c51c027ea/mailnews/base/src/nsMsgAccountManager.cpp#640

Thus accessing it results in a crash. This happens during cleanup when we try to remove the accounts created by the tests. I'll investigate.

Flags: needinfo?(brendan)

(In reply to Magnus Melin [:mkmelin] from comment #9)

This is also causing the perma comm/mail/services/sync/test/unit/test_server_tracker.js failure

Ah, indeed - I had managed to work around this issue but forgot to apply that workaround when removing the root folder. The fix is fairly simple, but I'll wait to see if the cause for the crash is similar enough that I can lump both fixes in the same patch.

Status: RESOLVED → REOPENED
Resolution: FIXED → ---

IM/chat accounts have a partial, synthetic representation of their folders that
doesn't map to on-disk paths; so they should be excluded from anything to do
with the folder cache.

This patch also loosens up the error handling when removing an account's root
folder from the cache, which was an oversight from the original patch (and also
lowers the logs from errors to warnings, in order to avoid triggering
assertions).

Attachment #9480304 - Attachment is obsolete: true

I've updated the initial patch to fix the test failures and crash.

Pushed by heather@thunderbird.net:
https://hg.mozilla.org/comm-central/rev/cf66e941f024
Remove folders from the folder cache on account removal. r=heather

Status: REOPENED → RESOLVED
Closed: 11 months ago11 months ago
Resolution: --- → FIXED

Looks like comm/mail/base/test/browser/browser_statusFeedback.js is perma-failing due to this

Flags: needinfo?(brendan)

Pushed by heather@thunderbird.net:
https://hg.mozilla.org/comm-central/rev/2a18a1ddda98
revert mail/base/test/browser/browser_statusFeedback.js changes that are causing failure. r=babolivier

Backout by mkmelin@iki.fi: https://hg.mozilla.org/comm-central/rev/e5e1a031b5cf Backed out changeset cf66e941f024
Attachment #9480940 - Attachment is obsolete: true
Flags: needinfo?(brendan)
Target Milestone: 139 Branch → 140 Branch

Pushed by brendan@thunderbird.net:
https://hg.mozilla.org/comm-central/rev/8b032f3ad1ad
Remove folders from the folder cache on account removal. r=heather

Status: REOPENED → RESOLVED
Closed: 11 months ago10 months ago
Resolution: --- → FIXED
See Also: 1897313
See Also: → 1989854
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: