From 0cc17a66e742f093a1f7998c2878915e06940afe Mon Sep 17 00:00:00 2001 From: Alexandre Poirot Date: Mon, 25 May 2020 06:29:51 +0000 Subject: [PATCH] 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 --- devtools/server/actors/targets/content-process.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/devtools/server/actors/targets/content-process.js b/devtools/server/actors/targets/content-process.js index 7aa3b6155995..db41fb39a0a8 100644 --- a/devtools/server/actors/targets/content-process.js +++ b/devtools/server/actors/targets/content-process.js @@ -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"); }, });