Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

service worker: Don't crash if respondWith() is called in a microtask. #15851

Closed
wants to merge 1 commit into from

Conversation

chromium-wpt-export-bot
Copy link
Collaborator

The RespondWithObserver and WaitUntilObserver interaction is tricky.
Essentially WaitUntilObserver determines when the fetch event is
finished. RespondWithObserver determines what the response to the
event is. The response is expected to be determined before the event
finishes.

We had a bug where the fetch event could finish before the response was
determined. RespondWithObserver depends on WaitUntilObserver to keep the
event alive until the respondWith() promise settles, but in some cases
WaitUntilObserver would silently ignore the promise.

One easy repro was when respondWith() was called in a microtask
immediately after event dispatch. This would cause a crash in
DidDispatchFetchEvent() since the event ended but the response callback
was still unconsumed.

The fix is to ensure WaitUntilObserver observes the promise, and in
cases that it won't, have RespondWithObserver properly handle the
respondWith() by throwing an exception and not advancing to state
kPending where it would wait for the promise to settle. So now, once
DidDispatchEvent() is called, RespondWithObserver knows it has no
outstanding promise and reports back that respondWith() was
effectively not called, so the browser falls back to network.

This also removes some early returns when the execution context is null,
which made it more unclear when the promises would be observed. It
should only be necessary to check the execution context when the context
is about to be accessed.

Bug: 941875
Change-Id: I14f008f7e76ec76d90fe25104cc6f3849808fb2f
Reviewed-on: https://chromium-review.googlesource.com/1523207
WPT-Export-Revision: 024e25a47b9eb11b5fb81744fccbe09d52cdda5e

The RespondWithObserver and WaitUntilObserver interaction is tricky.
Essentially WaitUntilObserver determines when the fetch event is
finished.  RespondWithObserver determines what the response to the
event is. The response is expected to be determined before the event
finishes.

We had a bug where the fetch event could finish before the response was
determined. RespondWithObserver depends on WaitUntilObserver to keep the
event alive until the respondWith() promise settles, but in some cases
WaitUntilObserver would silently ignore the promise.

One easy repro was when respondWith() was called in a microtask
immediately after event dispatch. This would cause a crash in
DidDispatchFetchEvent() since the event ended but the response callback
was still unconsumed.

The fix is to ensure WaitUntilObserver observes the promise, and in
cases that it won't, have RespondWithObserver properly handle the
respondWith() by throwing an exception and not advancing to state
kPending where it would wait for the promise to settle. So now, once
DidDispatchEvent() is called, RespondWithObserver knows it has no
outstanding promise and reports back that respondWith() was
effectively not called, so the browser falls back to network.

This also removes some early returns when the execution context is null,
which made it more unclear when the promises would be observed. It
should only be necessary to check the execution context when the context
is about to be accessed.

Bug: 941875
Change-Id: I14f008f7e76ec76d90fe25104cc6f3849808fb2f
Copy link
Collaborator

@wpt-pr-bot wpt-pr-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already reviewed downstream.

@KyleJu
Copy link
Contributor

KyleJu commented May 10, 2019

Close this PR because the Chromium CL does not have exportable changes.

@KyleJu KyleJu closed this May 10, 2019
@KyleJu KyleJu deleted the chromium-export-cl-1523207 branch May 10, 2019 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants