Skip to content

Commit

Permalink
feat: add locking mechanism for Network.loadingFailed and Network.eve…
Browse files Browse the repository at this point in the history
…ntSourceMessageReceived
  • Loading branch information
nilshah98 committed Nov 24, 2023
1 parent 63ec621 commit 8fb51fc
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/core/src/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,11 @@ export class Network {

// Called when a request streams events. These types of requests break asset discovery because
// they never finish loading, so we untrack them to signal idle after the first event.
_handleEventSourceMessageReceived = event => {
let request = this.#requests.get(event.requestId);
_handleEventSourceMessageReceived = async event => {
let { requestId } = event;
// wait for request to be sent
await this.#requestsLifeCycleHandler.get(requestId).checkRequestSent;
let request = this.#requests.get(requestId);
/* istanbul ignore else: race condition paranioa */
if (request) this._forgetRequest(request);
}
Expand All @@ -262,7 +265,13 @@ export class Network {
}

// Called when a request has failed loading and triggers the this.onrequestfailed callback.
_handleLoadingFailed = event => {
_handleLoadingFailed = async event => {
let { requestId } = event;
// wait for request to be sent
// note: we are waiting on checkRequestSent and NOT checkResponseSent
// since, requests can be cancelled in-flight without Network.responseReceived having been triggered
// and in any case, order of processing for responseReceived and loadingFailed does not matter, as response capturing is done in loadingFinished
await this.#requestsLifeCycleHandler.get(requestId).checkRequestSent
let request = this.#requests.get(event.requestId);
/* istanbul ignore if: race condition paranioa */
if (!request) return;
Expand Down

0 comments on commit 8fb51fc

Please sign in to comment.