From 2b1f4866a98c125c5c159a89b5fa98405aee2e2b Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 9 Apr 2021 14:25:19 +0200 Subject: [PATCH] map unexpected fetch AbortError to ConnectionError, so doesn't stop sync --- src/matrix/net/HomeServerApi.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/matrix/net/HomeServerApi.js b/src/matrix/net/HomeServerApi.js index f8dfa517..b93dac91 100644 --- a/src/matrix/net/HomeServerApi.js +++ b/src/matrix/net/HomeServerApi.js @@ -47,7 +47,23 @@ class RequestWrapper { }, err => { // if this._requestResult is still set, the abort error came not from calling abort here if (err.name === "AbortError" && this._requestResult) { - const err = new Error(`Unexpectedly aborted, see #187.`); + // The service worker sometimes (only on Firefox, on long, large request, + // perhaps it has its own timeout?) aborts the request, see #187. + // When it happens, the best thing to do seems to be to retry. + // + // In the service worker, we will also actively abort requests when trying to + // get a new service worker to activate, as the service worker will only be replaced + // when there are no more (fetch) events for the current one to handle. + // + // In that case, the request function (in fetch.js) will check + // the haltRequests flag on the service worker handler, and it will + // actually not do any requests, as that would break the update process. + // + // So it is OK to return a timeout ConnectionError here. + // If we're updating the service worker, the /versions polling will + // actually be blocked at the fetch level because haltRequests is set. + // And for #187, retrying is the right thing to do. + const err = new ConnectionError(`Service worker aborted, either updating or hit #187.`, true); log?.catch(err); throw err; } else {