Closed Bug 1399646 Opened 7 years ago Closed 7 years ago

Fix shutdown issues with StreamFilters in use (and otherwise)

Categories

(WebExtensions :: Request Handling, defect, P1)

defect

Tracking

(firefox57 affected)

RESOLVED FIXED
Tracking Status
firefox57 --- affected

People

(Reporter: kmag, Assigned: kmag)

References

Details

Attachments

(4 files)

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 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)
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 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 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 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+
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
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 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+
https://hg.mozilla.org/integration/mozilla-inbound/rev/4890481365e66c1ef2f7126481908b64002c113f
Bug 1399646: Part 2 - Use the async shutdown service for ServiceWorkerRegistrar. r=baku
Depends on: 1403348
Depends on: 1403692
Priority: -- → P1
Status: NEW → RESOLVED
Closed: 7 years ago
Keywords: leave-open
Resolution: --- → FIXED
No longer blocks: 1398685
Product: Toolkit → WebExtensions
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: