FetchEvent.respondWith is terminated in 70 seconds in ServiceWorker

Hi, there.

I am trying to use ServiceWorker on iPad to retry a request that has a communication error. However, I am having trouble with the process being terminated after 70 seconds. Occurs at least on iPadOS 17.6.1 and 16.3. The following is the service worker code to reproduce the problem:

self.addEventListener('fetch', (event) => {
 if (event.request.url.includes('test.html')) {
  event.respondWith(longRunFetch());
 }
});

async function longRunFetch(request) {
 await new Promise(resolve => setTimeout(resolve, 75000));

 return new Response('Fetch completed');
}

When this code is executed on an iPad and a request is made to test.html, the service worker stops after about 70 seconds. When it stops, it falls back to the network request and the contents of test.html are displayed. The service worker thread appears to be killed and is unavailable until the browser is restarted. If timeout is set to 65000, 'Fetch completed' is displayed as expected.

  • Why is the process terminated in 70 seconds?
  • Is there any way to continue processing beyond 70 seconds?
FetchEvent.respondWith is terminated in 70 seconds in ServiceWorker
 
 
Q