Closed Bug 1174381 Opened 9 years ago Closed 9 years ago

ServiceWorkerManager shutdown violates XPCOM threading rules and leaks

Categories

(Core :: DOM: Service Workers, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla41
Tracking Status
firefox41 --- fixed

People

(Reporter: jesup, Assigned: baku)

References

Details

(Keywords: memory-leak)

Attachments

(1 file)

Since the recent landing of bug 1155153 (I think), the ServiceWorkerManager code is using DispatchToMainThread() from nsComponentManagerImpl::gComponentManager->FreeServices() in XPCOM shutdown - this happens after xpcom-shutdown-threads, nsThreadManager shutdown, etc.  At this point DispatchToMainThread() will always fail and leak, which is what I've been seeing with some dispatch changes I've been working on.

This is trying to send a Shutdown message via mActor (i.e. PBackground IPC).  Of course, it's way too late to do so at this point.  Likely this needs to occur at xpcom-shutdown or even xpcom-will-shutdown (earlier?).

It's especially ironic as the DispatchToMainThread call is being made from Mainthread.

Compare https://treeherder.mozilla.org/#/jobs?repo=try&revision=16d4ff3305c8 to https://treeherder.mozilla.org/#/jobs?repo=try&revision=1c1a548aac7a, which are the same code under 'try' sitting on top of a different base (first is the 'after' shot; second Try link is the 'first' Try link.
Even slightly more ironically, if the Dispatch had succeeded I think it would have asserted, as SendShutdown() (in TeardownRunnable) is worker-thread-only (I tried replacing the Dispatch with just a call to the SendShutdown() directly and it asserted).  I'd previously verified (at least in a non-e10s run) that ~ServiceWorkerManager() runs on MainThread() (per comment 0 here).

Side note: AssertWorkerThread() called that late in shutdown causes an ASAN hit as well.  Of course, one shouldn't be doing that. (NI-ing bent on this - something in "MOZ_RELEASE_ASSERT(mWorkerLoopID == MessageLoop::current()->id(), "...."); is reading freed memory in that case, perhaps MessageLoop::current() is returning a stale ptr.
Flags: needinfo?(bent.mozilla)
Component: DOM: Workers → DOM: Service Workers
Flags: needinfo?(nsm.nikhil)
Flags: needinfo?(bkelly)
Flags: needinfo?(bent.mozilla)
Andrea, Nikhil, do you have any ideas here?  I'm not that familiar with the ServiceWorkerManager threading model.
Flags: needinfo?(bkelly) → needinfo?(amarchesini)
Assignee: nobody → amarchesini
Flags: needinfo?(amarchesini)
Flags: needinfo?(nsm.nikhil)
Attached patch patchSplinter Review
Attachment #8623715 - Flags: review?(nsm.nikhil)
Comment on attachment 8623715 [details] [diff] [review]
patch

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

::: dom/workers/ServiceWorkerManager.cpp
@@ +4425,5 @@
>      }
>  
>      RemoveAllRegistrations(principal);
>    } else if (strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0) {
> +    mShuttingdown = true;

This is mShuttingDown
Comment on attachment 8623715 [details] [diff] [review]
patch

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

::: dom/workers/ServiceWorkerManager.cpp
@@ +2352,5 @@
>        registration->Clear();
>        swm->RemoveRegistration(registration);
>      }
>  
> +    // Could it be that we are shutting down.

"We could be shutting down."
Attachment #8623715 - Flags: review?(nsm.nikhil) → review+
https://hg.mozilla.org/mozilla-central/rev/1019348c7786
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla41
Depends on: 1184807
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: