Skip to content

Commit

Permalink
fix race condition between caching and aborting (#8472)
Browse files Browse the repository at this point in the history
fix #8470, continuous memory usage growth
  • Loading branch information
ansis authored Jul 16, 2019
1 parent 5e9686c commit 4e3a785
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/util/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ function makeFetchRequest(requestParameters: RequestParameters, callback: Respon
signal: controller.signal
});
let complete = false;
let aborted = false;

const cacheIgnoringSearch = hasCacheDefeatingSku(request.url);

Expand All @@ -110,6 +111,8 @@ function makeFetchRequest(requestParameters: RequestParameters, callback: Respon
}

const validateOrFetch = (err, cachedResponse, responseIsFresh) => {
if (aborted) return;

if (err) {
// Do fetch in case of cache error.
// HTTP pages in Edge trigger a security error that can be ignored.
Expand Down Expand Up @@ -152,6 +155,7 @@ function makeFetchRequest(requestParameters: RequestParameters, callback: Respon
requestParameters.type === 'json' ? response.json() :
response.text()
).then(result => {
if (aborted) return;
if (cacheableResponse && requestTime) {
// The response needs to be inserted into the cache after it has completely loaded.
// Until it is fully loaded there is a chance it will be aborted. Aborting while
Expand All @@ -172,6 +176,7 @@ function makeFetchRequest(requestParameters: RequestParameters, callback: Respon
}

return { cancel: () => {
aborted = true;
if (!complete) controller.abort();
}};
}
Expand Down

0 comments on commit 4e3a785

Please sign in to comment.