Fix shutdown issues with StreamFilters in use (and otherwise)

RESOLVED FIXED

Status

WebExtensions
Request Handling
P1
normal
RESOLVED FIXED
9 months ago
5 days ago

People

(Reporter: kmag, Assigned: kmag)

Tracking

(Depends on: 2 bugs)

unspecified
Dependency tree / graph

Firefox Tracking Flags

(firefox57 affected)

Details

MozReview Requests

Submitter Diff Changes Open Issues Last Updated
Loading...
Error loading review requests:

Attachments

(4 attachments)

(Assignee)

Description

9 months ago
There are currently some shutdown issues when StreamFilters in a child process are active for requests in the parent.

The main issue is that the combination of the BackgroundPageThumbs service running during shutdown along with unexpected reentrancy in the service worker registrar tends to cause deadlocks at shutdown for short sessions (as triggered by ts_paint tests). That results in the process being killed before it gets passed the profile-before-change shutdown phase, and the background threads therefore shutting down before the actors have had a chance to clean up after themselves.

Aside from that, we don't do a particularly good job of making sure StreamFilter instances are closed as soon as possible after the page they belong to is closed. There are probably more elegant ways we should handle that, but my current solution is to disconnect the actor as soon as we try to dispatch an event to a page that has scriptability blocked.
Comment hidden (mozreview-request)
Comment hidden (mozreview-request)
Comment hidden (mozreview-request)
Comment hidden (mozreview-request)

Comment 5

9 months ago
mozreview-review
Comment on attachment 8907847 [details]
Bug 1399646: Part 1 - Destroy BackgroundPageThumbs instance at shutdown.

https://reviewboard.mozilla.org/r/179534/#review184720

::: commit-message-43d65:8
(Diff revision 1)
> +Calling the (currently unused) _destroy() method at the start of shutdown
> +seems to prevent the majority of these problems.

Doesn't look unused:

https://dxr.mozilla.org/mozilla-central/source/testing/mochitest/browser-test.js#634


Does that mean we should be removing that callsite?
Attachment #8907847 - Flags: review?(gijskruitbosch+bugs)
(Assignee)

Comment 6

9 months ago
mozreview-review-reply
Comment on attachment 8907847 [details]
Bug 1399646: Part 1 - Destroy BackgroundPageThumbs instance at shutdown.

https://reviewboard.mozilla.org/r/179534/#review184720

> Doesn't look unused:
> 
> https://dxr.mozilla.org/mozilla-central/source/testing/mochitest/browser-test.js#634
> 
> 
> Does that mean we should be removing that callsite?

Hm. I couldn't find any uses of it, but I didn't check tests.

But, no, I don't think we should remove that call site, since it's there to prevent false positive window leak failures for windows created by the background thumbs service. I think the shutdown observer happens too late to handle that.

But the `_destroy()` method can handle being called multiple times, so I don't think having both is a problem.

Comment 7

9 months ago
mozreview-review
Comment on attachment 8907847 [details]
Bug 1399646: Part 1 - Destroy BackgroundPageThumbs instance at shutdown.

https://reviewboard.mozilla.org/r/179534/#review184726

OK, then let's do it.
Attachment #8907847 - Flags: review+

Comment 8

9 months ago
mozreview-review
Comment on attachment 8907850 [details]
Bug 1399646: Part 4 - Increase the extension shutdown blocker timeout.

https://reviewboard.mozilla.org/r/179540/#review184732
Attachment #8907850 - Flags: review?(mixedpuppy) → review+

Comment 9

9 months ago
mozreview-review
Comment on attachment 8907849 [details]
Bug 1399646: Part 3 - Improve handling of StreamFilters at shutdown.

https://reviewboard.mozilla.org/r/179538/#review184734

I'm not familiar with xpc::Scriptability, but what you're doing looks reasonable.
Attachment #8907849 - Flags: review?(mixedpuppy) → review+
(Assignee)

Comment 10

9 months ago
https://hg.mozilla.org/integration/mozilla-inbound/rev/8220fde3db60b243e9d8b8abd82562bb31509deb
Bug 1399646: Part 1 - Destroy BackgroundPageThumbs instance at shutdown. r=Gijs

https://hg.mozilla.org/integration/mozilla-inbound/rev/f87e1d6810536ab0dc940f95563869d86aa937d3
Bug 1399646: Part 3 - Improve handling of StreamFilters at shutdown. r=mixedpuppy

https://hg.mozilla.org/integration/mozilla-inbound/rev/c7c638b31626ace9d0951e7a69450615673c9656
Bug 1399646: Part 4 - Increase the extension shutdown blocker timeout. r=mixedpuppy
(Assignee)

Comment 11

9 months ago
The three parts I pushed should be enough to fix most of the talos failures, but there will probably be intermittents until the last part lands.
Keywords: leave-open

Comment 13

9 months ago
mozreview-review
Comment on attachment 8907848 [details]
Bug 1399646: Part 2 - Use the async shutdown service for ServiceWorkerRegistrar.

https://reviewboard.mozilla.org/r/179536/#review184924

::: dom/workers/ServiceWorkerRegistrar.cpp:1029
(Diff revision 1)
>    }
>  
> +  rv = GetShutdownPhase()->AddBlocker(
> +    this, NS_LITERAL_STRING(__FILE__), __LINE__,
> +    NS_LITERAL_STRING("ServiceWorkerRegistrar"));
> +  MOZ_ASSERT(NS_SUCCEEDED(rv));

if (NS_WARN_IF(NS_FAILED(rv))) {
  return;
}

::: dom/workers/ServiceWorkerRegistrar.cpp:1080
(Diff revision 1)
> +}
> +
> +NS_IMETHODIMP
> +ServiceWorkerRegistrar::GetName(nsAString& aName)
> +{
> +  aName = NS_LITERAL_STRING("ServiceWorkerRegistar");

This should be "ServiceWorkerRegistrar: Flushing data" or anything with a meaning.

::: dom/workers/ServiceWorkerRegistrar.cpp:1099
(Diff revision 1)
> +  MOZ_RELEASE_ASSERT(svc);
>  
> -  MOZ_ALWAYS_TRUE(SpinEventLoopUntil([&]() { return completed; }));
> +  nsCOMPtr<nsIAsyncShutdownClient> client;
> +  Unused << svc->GetProfileBeforeChange(getter_AddRefs(client));
> +  MOZ_RELEASE_ASSERT(client);
> +  return Move(client);

Is Move(client) equal to client.forget() ? I guess so.
Attachment #8907848 - Flags: review?(amarchesini) → review+
(Assignee)

Comment 14

9 months ago
https://hg.mozilla.org/integration/mozilla-inbound/rev/4890481365e66c1ef2f7126481908b64002c113f
Bug 1399646: Part 2 - Use the async shutdown service for ServiceWorkerRegistrar. r=baku

Updated

9 months ago
status-firefox57: --- → affected

Updated

9 months ago
Depends on: 1403348

Updated

9 months ago
Depends on: 1403692

Updated

9 months ago
Priority: -- → P1

Updated

8 months ago
Status: NEW → RESOLVED
Last Resolved: 8 months ago
Keywords: leave-open
Resolution: --- → FIXED
No longer blocks: 1398685

Updated

5 days ago
Product: Toolkit → WebExtensions
You need to log in before you can comment on or make changes to this bug.