Bug 1389381: Part 1 - Synchronously remove rending responses after aborting them. r?aswan draft
authorKris Maglione <maglione.k@gmail.com>
Fri, 11 Aug 2017 14:37:53 -0700
changeset 645101 cae004dbbc0e477fa18d2abc829ab711be81a782
parent 645100 3849a13bc8ced0a25d30a466a4027d4934ab4941
child 645102 09ec4a7a5a421ce73596d58e31f7150774d4dfcc
child 645323 767c494324db1160a24a76ae82947ed5ff1fd9dd
push id73664
push usermaglione.k@gmail.com
push dateFri, 11 Aug 2017 21:50:09 +0000
reviewersaswan
bugs1389381
milestone57.0a1
Bug 1389381: Part 1 - Synchronously remove rending responses after aborting them. r?aswan Pending responses are normally removed by the response's promise handlers. But since promise handlers are called asynchronously, multiple calls to abortResponses can wind up handling the same already-aborted responses when called before we process the microtask queue. MozReview-Commit-ID: 4jy0O7PaoqP
toolkit/components/extensions/MessageChannel.jsm
--- a/toolkit/components/extensions/MessageChannel.jsm
+++ b/toolkit/components/extensions/MessageChannel.jsm
@@ -777,16 +777,17 @@ this.MessageChannel = {
    * @param {object} [reason]
    *    An optional object describing the reason the response was aborted.
    *    Will be passed to the promise rejection handler of all aborted
    *    responses.
    */
   abortResponses(sender, reason = this.REASON_DISCONNECTED) {
     for (let response of this.pendingResponses) {
       if (this.matchesFilter(sender, response.sender)) {
+        this.pendingResponses.delete(response);
         this.abortedResponses.add(response.channelId);
         response.reject(reason);
       }
     }
   },
 
   /**
    * Aborts any pending message responses to the broker for the given