Closed Bug 870864 Opened 12 years ago Closed 8 years ago

nsImapProtocol uses wrapped JS objects off the main thread

Categories

(MailNews Core :: Networking: IMAP, defect)

defect
Not set
normal

Tracking

(seamonkey2.21?, thunderbird_esr2426+)

RESOLVED FIXED
Thunderbird 51.0
Tracking Status
seamonkey2.21 ? ---
thunderbird_esr24 26+ ---

People

(Reporter: jdm, Assigned: rkent)

References

Details

Attachments

(4 files, 2 obsolete files)

This stuff needs to use nsMainThreadPtrHolder. See the dependent bugs of bug 773610 for examples.
It's possible that the problem is the nsIMsgWindow nsCOMPtr in TryToLogon, since I see various tests implementing JS versions of that.
Summary: ImapProtocol uses wrapped JS objects off the main thread → nsImapProtocol uses wrapped JS objects off the main thread
There were mozmill crashes on c-c too. Don't know if they had the same root cause or not.
I think all the uses of the msg window are on the main thread, but I'm testing a patch which uses the wrapper right now. Damn IDL...
TryToLogon is used off the main thread and it obtains the nsIMsgWindow interface into an nsCOMPtr which would trigger the abort if it's implemented by a JS object.
When I said "use", I meant any actual calls beyond implicit AddRef/Release (the *sink calls is also synchronously proxied back to the main thread). Since I pulled from the m-c just after the backout had been applied, I haven't verified that the crash is fixed yet.
OS: Linux → All
Hardware: x86_64 → All
I tried to dig in, but it appeared more complicated than I originally anticipated. Joshua, I'm hoping to reland the original abort in the next couple days, so it would be great if you could tackle this.
I don't know if this actually stops the assertion failure or not.
Attachment #754606 - Flags: review?(Pidgeot18) → review?(mozilla)
Assignee: nobody → josh
IMHO this is the wrong fix; all the IMAP tests should be using real nsMsgWindow objects. The openFolder attribute isn't even readonly!
(We could fix the alerts test and make nsIMsgWindow builtinclass but that would be harder and probably deserves its own bug.)
Attachment #760943 - Flags: review?(neil)
Attachment #760943 - Attachment is obsolete: true
Attachment #760943 - Flags: review?(neil)
Comment on attachment 760949 [details] [diff] [review]
Disable tests until a proper fix is provided.

> [test_imapAttachmentSaves.js]
>+# Disabled until bug 870864 is resolved
>+skip-if = true
...
> [test_imapHdrChunking.js]
>+# Disabled until bug 870864 is resolved
>+skip-if = true
I'd spotted these tests misusing nsIMsgWindow but I hadn't realised that there were so many others :-(

> [test_offlineStoreLocking.js]
>-# Doesn't currently work on Windows, bug 782625
>-skip-if = os == "win"
>+# Disabled until bug 870864 is resolved
>+skip-if = true
Please leave the Windows comment in, just in case someone erroneously tries to enable it on all platforms.
Attachment #760949 - Flags: review?(neil) → review+
Setting as tracking-thunderbird24+. I'm uneasy with the idea of a release with all these tests disabled.
Any such release will be crashing regularly when using IMAP, fwiw, so there should be little chance of that happening.
Actually, that's wrong. I forgot that only the tests use the JS-implemented message window, not the actual app.
Anybody else want to take the review here?
Comment on attachment 754606 [details] [diff] [review]
Make IMAP protocol avoid addreffing potentially non-threadsafe windows off the main thread.

Neil, can you take a look at this?
Attachment #754606 - Flags: review?(mozilla) → review?(neil)
Comment on attachment 754606 [details] [diff] [review]
Make IMAP protocol avoid addreffing potentially non-threadsafe windows off the main thread.

I already did, see comment #11.
Attachment #754606 - Flags: review?(neil) → review?(mbanner)
Comment on attachment 754606 [details] [diff] [review]
Make IMAP protocol avoid addreffing potentially non-threadsafe windows off the main thread.

Sorry for not really looking earlier. I think we need to fix the tests as Neil suggests, I'm not quite sure that's very easy, but it seems the better fix in the long run.
Attachment #754606 - Flags: review?(mbanner) → review-
Let's not pretend that I'm actually working on this.
Assignee: josh → nobody
kent, can you suggest someone who might be able to work on this?
Flags: needinfo?(kent)
Whiteboard: [leave open] → [leave open][patchlove]
Attached patch 870864.patch (obsolete) — Splinter Review
If the approach in comment 11 can be done this way, then perhaps this will fix this.

Otherwise either Joshua or Neil would probably be good candidates to try to fix the msgWindow. But if this is only a testing issue, I would prefer we just fix the testing issue.
Flags: needinfo?(kent)
Attachment #8541304 - Flags: review?(neil)
Comment on attachment 8541304 [details] [diff] [review]
870864.patch

I'm not sure you need to override authPrompt because the login manage provides the default auth prompt anyway.

I'm not even sure you need to override the prompt dialog, since alertUtilsPrompts already overrides both the window watcher and the prompt service.

You obviously don't need to override them in the IMAP case. Does the POP case actually try to access them off the main thread?

But if you do need to override them, I'd prefer if you added a testing interface with the method to override the prompt dialog.
Attachment #8541304 - Flags: review?(neil) → feedback+
With a few additional fixes, I don't need to override them, with one exception:

In test_imapPasswordFailure, the password dialog fails due to this code in nsMsgIncomingServer:

  if (m_password.IsEmpty())
  {
    nsCOMPtr<nsIAuthPrompt> dialog;
    // aMsgWindow is required if we need to prompt
    if (aMsgWindow)
    {
      rv = aMsgWindow->GetAuthPrompt(getter_AddRefs(dialog));
      NS_ENSURE_SUCCESS(rv, rv);
    }

which is calling:

NS_IMETHODIMP nsMsgWindow::GetAuthPrompt(nsIAuthPrompt * *aAuthPrompt)
{
  NS_ENSURE_ARG_POINTER(aAuthPrompt);
  if (!mRootDocShellWeak)
    return NS_ERROR_FAILURE;

Any suggestions of how to fix that with the override of authPrompt?
(In reply to Kent James (:rkent) from comment #28)
> 
> Any suggestions of how to fix that with the override of authPrompt?
Flags: needinfo?(neil)
Flags: needinfo?(Pidgeot18)
In the POP case since it's main-thread only are we just using a dummy msgWindow object which therefore can provide a dummy auth prompt?
Barring that, it may be possible to make the GetAuthPrompt method construct a new nsIAuthPrompt like the dummy message window did in the case that no docshell is available.
Flags: needinfo?(Pidgeot18)
I'm going to set myself as Assigned because I have a patch proposal here that I should look at some day, but I don;t make any claims to be actually working on this at the moment. If you are competent feel free to take this.
Assignee: nobody → rkent
Status: NEW → ASSIGNED
See Also: → 1133892
Kent, 
The imap area is rather fragile because of the lingering off main thrad issues. Can this be added to the bottom of your top priority stack?  Or suggest somone else?

clearing - neil replied.
Flags: needinfo?(neil) → needinfo?(rkent)
Wayne, there are just too many other things for me to work on between now and release of Thunderbird 45. Magnus would be another possibility, but he also already is doing alot.
Assignee: rkent → nobody
Status: ASSIGNED → NEW
Flags: needinfo?(rkent)
When adding a new test to mailnews/imap/test/unit/xpcshell.ini for bug 629738 I came across this bug which disables a bunch of tests. So what's the status of this? Your patch is really minimal. Does it solve the problem?
Flags: needinfo?(rkent)
Yes I believes it works, here is an updated patch with Neal's suggestion.
Assignee: nobody → rkent
Attachment #8541304 - Attachment is obsolete: true
Status: NEW → ASSIGNED
Flags: needinfo?(rkent)
Attachment #8791395 - Flags: review?(jorgk)
(In reply to Kent James (:rkent) from comment #36)
> Yes I believes it works, here is an updated patch with Neal's suggestion.
Great. Thanks. Try here:
https://treeherder.mozilla.org/#/jobs?repo=try-comm-central&revision=59186d0b7944
Comment on attachment 8791395 [details] [diff] [review]
Use a real window, add a test interface as Neal suggested

Review of attachment 8791395 [details] [diff] [review]:
-----------------------------------------------------------------

Looks good. Please disable the test that also fails on Mac. See try run.

::: mailnews/imap/test/unit/xpcshell.ini
@@ +63,5 @@
>  [test_offlinePlayback.js]
>  run-sequentially = Starts server twice.
>  [test_offlineStoreLocking.js]
>  # Doesn't currently work on Windows, bug 782625
> +skip-if = os == 'win'

Please check the try run to see that this also fails on Mac.
Attachment #8791395 - Flags: review?(jorgk) → review+
http://hg.mozilla.org/comm-central/rev/b133e1d1134c
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Whiteboard: [leave open][patchlove]
Target Milestone: --- → Thunderbird 51.0
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: