Bug 1636192 - Clean Content process Target actor on process shutdown. r=nchevobbe

Before this patch, we were not trying to cleanup anything when the process
was known to be in process of destruction. We assumed that everything would
be cleaned up anyway.
But mochitest is actually asserting that nothing is leaked on process shutdown,
and we are easily leaking many thing when not destroying the target actor!

Differential Revision: https://phabricator.services.mozilla.com/D76156
This commit is contained in:
Alexandre Poirot 2020-05-25 06:29:51 +00:00
Родитель 332fe1a094
Коммит 0cc17a66e7
1 изменённых файлов: 14 добавлений и 0 удалений

Просмотреть файл

@ -73,6 +73,15 @@ const ContentProcessTargetActor = ActorClassWithSpec(contentProcessTargetSpec, {
this._workerList = null;
this._workerTargetActorPool = null;
this._onWorkerListChanged = this._onWorkerListChanged.bind(this);
// Try to destroy the Content Process Target when the content process shuts down.
// The parent process can't communicate during shutdown as the communication channel
// is already down (message manager or JS Window Actor API).
// So that we have to observe to some event fired from this process.
// While such cleanup doesn't sound ultimately necessary (the process will be completely destroyed)
// mochitests are asserting that there is no leaks during process shutdown.
this.destroy = this.destroy.bind(this);
Services.obs.addObserver(this.destroy, "xpcom-shutdown");
},
get isRootActor() {
@ -181,6 +190,9 @@ const ContentProcessTargetActor = ActorClassWithSpec(contentProcessTargetSpec, {
},
destroy: function() {
if (!this.actorID) {
return;
}
Actor.prototype.destroy.call(this);
// Tell the live lists we aren't watching any more.
@ -198,6 +210,8 @@ const ContentProcessTargetActor = ActorClassWithSpec(contentProcessTargetSpec, {
this._dbg.disable();
this._dbg = null;
}
Services.obs.removeObserver(this.destroy, "xpcom-shutdown");
},
});