Intermittent comm/mailnews/imap/test/unit/test_offlinePlayback.js | Test timed out
Categories
(MailNews Core :: Networking: IMAP, defect, P5)
Tracking
(Not tracked)
People
(Reporter: intermittent-bug-filer, Assigned: john)
References
(Blocks 1 open bug)
Details
(Keywords: intermittent-failure, intermittent-testcase, Whiteboard: [collect_confirm_failure])
Attachments
(1 external file)
Filed by: john [at] thunderbird.net
Parsed log: https://treeherder.mozilla.org/logviewer?job_id=576837139&repo=comm-central&task=PBPdzCoPREOsSKdxM7SoXw.0
Full log: https://firefox-ci-tc.services.mozilla.com/api/queue/v1/task/PBPdzCoPREOsSKdxM7SoXw/runs/0/artifacts/public/logs/live_backing.log
| Assignee | ||
Comment 1•5 months ago
|
||
AI Summary (Anthropic Opus 4.8)
comm/mailnews/imap/test/unit/test_offlinePlayback.js intermittently times out (60s) and fails the checkDone assertion. Investigation shows this is a product defect in nsImapOfflineSync::ProcessAppendMsgOperation, not a test flake: an error path abandons the offline-sync state machine, turning a recoverable I/O failure into a permanent hang and a silently-dropped offline append.
Failure signature
- Test:
comm/mailnews/imap/test/unit/test_offlinePlayback.js(xpcshell, maildir store —xpcshell-maildir.toml) - Platform: Windows 11 64-bit
- Both the initial run and the retry failed identically:
TEST-UNEXPECTED-TIMEOUT | ... | Test timed out(~60s)TEST-FAIL | ... | checkDone - [checkDone : 134] null != null
- Two
WARNING: '(NS_FAILED(rv))', file .../comm/mailnews/imap/src/nsImapOfflineSync.cpp:362per run.
Example task: https://firefox-ci-tc.services.mozilla.com/api/queue/v1/task/PBPdzCoPREOsSKdxM7SoXw/runs/0 (changeset 625d41e6bf1f).
What the test does
The test goes offline, performs three operations, goes back online, and asserts all three were replayed:
| Offline op | Replayed to server? |
|---|---|
| copy msg1 → secondFolder | Yes (uid copy 1 "secondFolder") |
| copy msg2 → thirdFolder | Yes (uid copy 2 "thirdFolder") |
copyFileMessage(bugmail10) → INBOX (append) |
No — no APPEND ever sent |
A grep -i append over the entire CI log shows zero protocol APPEND commands. The offline append to INBOX was never played back, so getMsgHdrForMessageID(gMsgId1) returns null and the assertion at test_offlinePlayback.js:134 fails. The two flag/copy ops are fine.
Root cause
In nsImapOfflineSync::ProcessAppendMsgOperation (comm/mailnews/imap/src/nsImapOfflineSync.cpp):
rv = destFolder->GetMsgInputStream(mailHdr, getter_AddRefs(inStream));
if (NS_WARN_IF((NS_FAILED(rv)))) break; // line 361-362
Reading the offline-stored copy of the just-appended message back out of the maildir store intermittently fails. When it does, two things go wrong:
-
The append is silently dropped. The
breakhappens beforesetPlayingBack = true, soCopyFileMessageis never issued (noAPPEND), and the offline op is left in the DB. It is retried onupdateInboxand fails again (the secondcpp:362warning). Result:msgHdr3 == null. -
The offline-sync state machine stalls — this is the hang.
ProcessAppendMsgOperationonly continues the state machine via the asyncCopyFileMessage→OnStopCopy→ProcessNextOperation(). Every early exit that bypassesCopyFileMessage— thebreakat line 362 and the barereturns at lines 339, 343, and 348 — never callsProcessNextOperation(). Compare the header-missing path at lines 329-332, which correctly doesProcessNextOperation(); return;. So whenGetMsgInputStreamfails, the sync run never completes, its URL never receivesOnStopRunningUrl, and the run sits in the event loop until the 60s timeout fires.
This would hang a real user's offline playback the same way — the account would sit "playing back" indefinitely.
Why intermittent
GetMsgInputStream on the freshly-appended maildir message usually succeeds; under the right load/timing it fails to open the offline copy (note also the uid validity ... blowing away db warnings during the run). Most machines never hit it; this worker hit it on both attempts. The intermittency is only about whether GetMsgInputStream trips — the mishandling of that failure is deterministic and always wrong.
Proposed fix
- Hang fix (primary): Make every failure path in
ProcessAppendMsgOperationadvance the state machine — callProcessNextOperation()before returning (and decide deliberately whether to keep or clear the op) — so a failed append can no longer deadlock the entire offline sync. This is structurally correct regardless of the underlying trigger. - Trigger (secondary): Separately investigate why
GetMsgInputStreamfails for an offline-appended maildir message on Windows (e.g. storeToken not persisted / DB-reset race). The hang fix makes it non-fatal; this addresses the actually-missing message.
Affected files
comm/mailnews/imap/src/nsImapOfflineSync.cpp— defect (ProcessAppendMsgOperation, lines ~323-412).comm/mailnews/imap/test/unit/test_offlinePlayback.js— the test that catches it.
Note
This diagnosis is derived from the CI log plus source reading; it has not yet been reproduced locally. The state-machine gap is directly visible in the code and fully explains the hang. The reason GetMsgInputStream fails on Windows/maildir is not yet confirmed.
| Assignee | ||
Comment 2•5 months ago
|
||
So fixing the hang is just a product-robustness fix. The test will still fail, as I think the message will be missing. So both parts of the proposed fix are needed. But fixing the hang might already help because we might get a cleaner fail info?
| Assignee | ||
Comment 3•5 months ago
|
||
This is only the state-machine / hang fix. It does NOT fix the root trigger:
when GetMsgInputStream intermittently fails, the append is still not replayed
and the message remains missing (the checkDone assertion would still fail, just
without the 60s hang). Why the offline-store read intermittently fails is left
for a follow-up.
See the bug for more details.
Updated•5 months ago
|
| Comment hidden (Intermittent Failures Robot) |
| Assignee | ||
Comment 5•5 months ago
|
||
So fixing the hang is just a product-robustness fix. The test will still fail, as I think the message will be missing. So both parts of the proposed fix are needed. But fixing the hang might already help because we might get a cleaner fail info?
Updated•4 months ago
|
| Comment hidden (Intermittent Failures Robot) |
| Comment hidden (Intermittent Failures Robot) |
| Comment hidden (Intermittent Failures Robot) |
| Comment hidden (Intermittent Failures Robot) |
Comment 10•3 months ago
|
||
Reproduced locally on Linux, in both message stores - so this is neither Windows-specific nor limited to maildir.
Recipe: run the file on its own while the machine is busy (twelve spinning shell loops on eight cores here), and it fails about two runs in five. The whole mailnews/imap/test/unit suite hits it roughly one run in four, which is how I ran into it.
The GetMsgInputStream call has nothing left to read. Printing the header when it fails, at nsImapOfflineSync.cpp:383 (the line moved with bug 2057063):
rv=0x80004005 dest=imap://user@localhost/INBOX key=4294967168
token='' flags=0x00000000 offlineSize=0 msgId=''
The pseudo header for the offline append is there with its fake key, but it carries nothing at all: no message id, no store token, no Offline flag, size zero. That accounts for both symptoms from one cause - the stream cannot be opened, and checkDone's lookup by message id returns null because the header has no message id.
One correction to comment 1, if it helps: a passing run sends no APPEND either, and never reaches the stream call at all. So the absence of APPEND does not separate the two cases.
Comment 11•2 months ago
|
||
I noticed the test_offlinePlayback failed lately (after, I think, BenC's effort to clean up DB id and MsgKey separation).
My treeherder job recorded this.
I updated the local source files several days ago, and after lots of trials and errors, now I think I fixed the issue. The local test of test_offlinePlayback.js succeeds even under stress under stress-ng. Great.
Except, that the local patches are on top of my IMAP modification to make it free of TSAN-issues.
I have been working on make IMAP subsystem TSAN-issue free.
I have the local patches, but somehow it gets too big to be handled by moz-phab.
moz-phab seems to create additional local branches and patchsets during upload.
From the messed up HG tree status after failed moz-phab, I suspect the # of branches created during operation is O(n), and the # of changesets created is O(n^2) or larger, where 'n' is the number of patchsets in the tree to be uploaded. If n is around 20 or something, it is OK. But if n is about 100 as in my case, the data created during operation is too large and I think my /tmp runs out of space (or something) and thus moz-phab upload fails. It leaves a very messed up hg repository with branches and many changesets and it IS a real mess to clean it up. :-(
My observation about O(n) and O(n^2) is a guess after looking at the status of HG tree.
My local IMAP tree is TSAN-issue free and the long hung does not happen in the first place. It is transformed into a repetition of 60 seconds pause repeated forever. That is no longer observed after the latest fixes to the Playback code. And there are other niceties which may not be available in the unmodified TB source.
So, instead of trying to upload the IMAP modification to make it free of TSAN-issues, which seems to hit a wall right now,
I am trying to create an explanation of what changes are necessary for test_offlinePlayback.js to work.
BUT without referring to the patches created for my local tree, it is almost impossible to understand the changes.
I am hoping once the basic rationale behind my patches created against my local tree is understood, the patches can be modified to the upstream
TB repository by somebody
Maybe I can post the summary and the patches as reference data here, not in the phabricator for someone to port it to the upstream code.
Is this a right approach? Any good idea re how to proceed?
In the meantime, I am trying to split the patch sets for making IMAP TSAN-issue free into a few big chunks so that O(n) or O(n^2) data size issue won't kick in. I think from what I have seen 10-20 patchsets upload ought to work.
But it is slow going. Rearranging the order of 100 local HG MQ patches, some of them are quite large, to be separated into a logically separated groups that apply cleanly is not an easy job.
BTW, just like John, I had to use clause and chatgpt to figure out the subtle issues of replay mechanism. It was a very hairy debugging.
The code was full of worms as far as I can tell. Maybe it was not patched up to reflect the msgkey and db id dichotomy BenC tries to clean up.
However, I think there were bugs aside from them. Tough luck.
Comment 12•2 months ago
|
||
(In reply to ISHIKAWA, Chiaki from comment #11)
I noticed the test_offlinePlayback failed lately (after, I think, BenC's effort to clean up DB id and MsgKey separation).
I think there have been changes to make the test work, and my local patches have merge conflicts everywhere.
So maybe I should not post the local patches and let the upstream repository to settle down.
Updated•1 month ago
|
Updated•1 month ago
|
Description
•