Skip to content

Commit

Permalink
fix(service-worker): ensure SW stays alive while notifying clients ab…
Browse files Browse the repository at this point in the history
…out unrecoverable state (#40234)

Previously, the `Driver#notifyClientsAboutUnrecoverableState()` method
would not wait for the completion of the promises created to notify the
clients. Theoretically, this could result in the SW instance's getting
destroyed by the browser before all clients have been notified. This is
extremely unlikely to happen in practice, since the async operations are
very quick, but it _is_ theoretically possible.

This commit ensures that the SW instance will remain alive while
notifying the clients by making `notifyClientsAboutUnrecoverableState()`
await the notification promises.

PR Close #40234
  • Loading branch information
gkalpak authored and atscott committed Jan 11, 2021
1 parent ff36485 commit c01b5ea
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/service-worker/worker/src/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1026,10 +1026,10 @@ export class Driver implements Debuggable, UpdateSource {
.filter(([clientId, hash]) => hash === brokenHash)
.map(([clientId]) => clientId);

affectedClients.forEach(async clientId => {
await Promise.all(affectedClients.map(async clientId => {
const client = await this.scope.clients.get(clientId);
client.postMessage({type: 'UNRECOVERABLE_STATE', reason});
});
}));
}

async notifyClientsAboutUpdate(next: AppVersion): Promise<void> {
Expand Down

0 comments on commit c01b5ea

Please sign in to comment.