New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 602051 link

Starred by 9 users

Issue metadata

Status: Assigned
Owner:
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 3
Type: Bug

Blocking:
issue 678905
issue 915124
issue 914135



Sign in to add a comment

Sync XHR does not get intercepted by service worker

Project Member Reported by samccone@google.com, Apr 9 2016

Issue description

UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36

Example URL:
If you force your computer offline and issue a sync xhr request to a cached service worker route it will fail. However if you issue the exact same request with a non-sync xhr request it will correctly hit the service worker.

Steps to reproduce the problem:
1. visit https://www.moji-brush.com/
2. turn off your internet (via devtools network throttling or turn off your wifi)
3. Run this code

    var request = new XMLHttpRequest();
    request.open('GET', '', false);
    request.send(null);

Note how it fails..

now run this code

    var request = new XMLHttpRequest();
    request.open('GET', '', true);
    request.send(null);

Note how it works

What is the expected behavior?
sync should behave the same as non-sync

What went wrong?
The sync xhr request did not respect the service worker.

Did this work before? N/A 

Chrome version: 49.0.2623.110  Channel: n/a
OS Version: OS X 10.11.4
Flash Version: Shockwave Flash 21.0 r0
 
Components: -Internals>Network Blink>ServiceWorker Blink>Network>XHR Blink>ServiceWorker>Cache
Components: -Blink>ServiceWorker>Cache
Status: WontFix (was: Unconfirmed)
Synchronous XHR bypasses ServiceWorkers.

See  bug 413103 .

SW is skipped for sync loads at  https://code.google.com/p/chromium/codesearch#chromium/src/content/browser/loader/resource_dispatcher_host_impl.cc&sq=package:chromium&l=1598&rcl=1463008567
Cc: kenjibaheux@chromium.org jakearchibald@chromium.org
+kenjibaheux@, jakearchibald@

Tell me if this limitation is only for V1 and you have plan to relax it.

Comment 5 by falken@chromium.org, May 12 2016

Summary: Sync XHR does not get intercepted by service worker (was: Sync XHR does not respect service worker cache)
Retitling: "service worker cache" commonly refers to the Cache Storage API, which is not the point of this issue.

I'm not totally sure if this is spec'd or just something we implemented long ago.
I just checked the spec. It seems this behavior is not specced in the Fetch Standard.

Comment 7 by falken@chromium.org, May 12 2016

Labels: Needs-Feedback
Owner: jakearchibald@chromium.org
Status: Assigned (was: WontFix)
Jake, should service worker intercept sync XHR?
It should. Early on in Chrome's implementation, making sync XHR interceptable was really hard for some reason (caused a deadlock if memory serves), so it was intentionally skipped.

Is that still the case?

Comment 9 by falken@chromium.org, May 12 2016

Labels: -Pri-2 -Needs-Feedback -OS-Mac OS-All Pri-3
Owner: horo@chromium.org
Status: Available (was: Assigned)
OK. Tentatively assigning horo@. Setting to P3 since this limitation has been in our impl since inception.

Not sure if the deadlock would still be there... but probably since the basic architecture is still the same.

Comment 10 by horo@chromium.org, May 12 2016

Yes the deadlock issue is still there.

In the current implementation, the resource loading logic is executed in the main thread of the renderer process even when ServiceWorker fetches resources.
So if the ServiceWorker calls fetch() in the fetch event handler of the sync XHR, the deadlock happens because the main thread is blocked by the sync XHR.
Project Member

Comment 11 by sheriffbot@chromium.org, Jun 3 2016

Labels: Hotlist-Google

Comment 12 by horo@chromium.org, May 25 2017

 Issue 726327  has been merged into this issue.
Blocking: 678905
This will be fetch-request-xhr-sync.https.html once https://codereview.chromium.org/2907443002/ lands.
Project Member

Comment 14 by bugdroid1@chromium.org, Jun 1 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/7fdac9fc2a776ad2ed4c3df752896e0f33861b69

commit 7fdac9fc2a776ad2ed4c3df752896e0f33861b69
Author: mike <mike@mikepennisi.com>
Date: Thu Jun 01 16:44:45 2017

Upstream service worker "XHR" test to WPT

The original version of this test would only pass if the service worker
did *not* intercept the XHR request. That behavior conflicted with the
Fetch and Service Worker specification and with the test's documentation
itself. Update the test to pass only if the service worker intercepts
the request.

In addition:

- Update URLs to suitable values for the Web Platform Tests project
- Add "use strict" directives to script bodies
- Increase precision of "cleanup" logic scheduling
- Re-name files to adhere to precent set by existing WPT tests
- Catch and report errors within Promise chain rather than relying on
  implicit reporting of uncaught errors.

BUG= 688116 , 602051
R=falken@chromium.org

Review-Url: https://codereview.chromium.org/2907443002
Cr-Commit-Position: refs/heads/master@{#476324}

[modify] https://crrev.com/7fdac9fc2a776ad2ed4c3df752896e0f33861b69/third_party/WebKit/LayoutTests/FlagExpectations/enable-network-service
[add] https://crrev.com/7fdac9fc2a776ad2ed4c3df752896e0f33861b69/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/fetch-request-xhr-sync.https-expected.txt
[add] https://crrev.com/7fdac9fc2a776ad2ed4c3df752896e0f33861b69/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/fetch-request-xhr-sync.https.html
[add] https://crrev.com/7fdac9fc2a776ad2ed4c3df752896e0f33861b69/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/resources/fetch-request-xhr-sync-iframe.html
[add] https://crrev.com/7fdac9fc2a776ad2ed4c3df752896e0f33861b69/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/resources/fetch-request-xhr-sync-worker.js
[delete] https://crrev.com/1704affd92a33a48072fa0dfb0a63af1853a493a/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/sync-xhr-doesnt-deadlock-iframe.html
[delete] https://crrev.com/1704affd92a33a48072fa0dfb0a63af1853a493a/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/sync-xhr-doesnt-deadlock.data
[delete] https://crrev.com/1704affd92a33a48072fa0dfb0a63af1853a493a/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/sync-xhr-doesnt-deadlock.js
[delete] https://crrev.com/1704affd92a33a48072fa0dfb0a63af1853a493a/third_party/WebKit/LayoutTests/http/tests/serviceworker/sync-xhr-doesnt-deadlock-expected.txt
[delete] https://crrev.com/1704affd92a33a48072fa0dfb0a63af1853a493a/third_party/WebKit/LayoutTests/http/tests/serviceworker/sync-xhr-doesnt-deadlock.html

Status: Assigned (was: Available)
Is this being worked on? Kinda blocked by servicification?
Any context for the ping? No plans to work on this specifically, except as part of the burn down for issue 678905.

Likely blocked on servicification and off-main-thread fetch to avoid deadlocks, might take a lot of care to ensure absolutely no deadlock occurs, probably more trouble than this bug is worth...

Comment 17 by evn@google.com, Jul 12 2017

Cc: evn@google.com
 Issue 834802  has been merged into this issue.
The dead lock should be gone now.
Cc: domfarolino@gmail.com
Given yhirano@'s comment, and the fact that the tests/expectations still indicate failures ([1] and [2]), are there any plans to get this working, or not really, since the sync XHR is deprecated? (Asking because I'm writing resource load priority layout tests for requests passing through SWs).

[1]: https://wpt.fyi/results/service-workers/service-worker/fetch-request-xhr-sync.https.html?aligned&label=stable
[2]: https://cs.chromium.org/chromium/src/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/fetch-request-xhr-sync.https-expected.txt?q=fetch-request-xhr-s&sq=package:chromium&g=0&l=1
I think we should fix this: sync XHR should go to the service worker. In fact it might just work automatically now if we remove the blocking per yhirano's comment. Would you be interested in taking this?
Cc: -domfarolino@gmail.com
Owner: domfarolino@gmail.com
Will take a look.
Blocking: 914135
Yep, just finished finals - thanks for the ping looking now.
Blocking: 915124

Comment 27 by falken@chromium.org, Today (12 hours ago)

Just a status update: we found at https://chromium-review.googlesource.com/c/chromium/src/+/1376738 there is probably still a deadlock/livelock somewhere.

Comment 28 by falken@chromium.org, Today (12 hours ago)

Labels: Hotlist-Interop

Sign in to add a comment