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

Failed to load resource: the server responded with a status of 504 (Gateway Timeout) #22362

Closed
chamikasandamal opened this issue Feb 22, 2018 · 9 comments
Labels
area: service-worker Issues related to the @angular/service-worker package type: bug/fix
Milestone

Comments

@chamikasandamal
Copy link

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

Angular service worker application throws following error

Failed to load resource: the server responded with a status of 504 (Gateway Timeout)
ng new my-project --service-worker

Expected behavior

It should not throw any exceptions

Minimal reproduction of the problem with instructions

ng new my-project --service-worker
ng build --prod
cd dist http-server -p 8080
Even with IIS host i can see the same issue.

What is the motivation / use case for changing the behavior?

Environment


Angular version: 5.2.6


Browser:
- [x] Chrome (desktop) version 64.0.3282.167
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: v9.5.0  
- Platform:  Windows 

Others:

@petebacondarwin petebacondarwin added area: service-worker Issues related to the @angular/service-worker package type: bug/fix labels Feb 22, 2018
@ngbot ngbot bot added this to the needsTriage milestone Feb 26, 2018
@EreckGordon
Copy link

EreckGordon commented Feb 28, 2018

I have ran into this same issue. Rather than open a new ticket, I will just add my findings here:

It seems to happen when you open chrome devtools.

I believe this is the line causing the problems, but not 100% sure:

return this.safeFetch(event.request);

NGSW Debug Info:

Driver state: NORMAL ((nominal))
Latest manifest hash: 194dd40f1434a36f13c49709bb82e2caf2ad706f
Last update check: 2s964u

=== Version 194dd40f1434a36f13c49709bb82e2caf2ad706f ===

Clients: 5a10d896-2b1e-43aa-890f-04b96017eb19, b1708689-20fc-4469-81da-ddbbc28ed406

=== Idle Task Queue ===
Last update tick: 3s69u
Last update run: 10s411u
Task queue:
 * check-updates-on-navigation

Debug log:

[15s420u] TypeError(Failed to execute 'fetch' on 'ServiceWorkerGlobalScope': 'only-if-cached' can be set only with 'same-origin' mode, TypeError: Failed to execute 'fetch' on 'ServiceWorkerGlobalScope': 'only-if-cached' can be set only with 'same-origin' mode
    at Driver.safeFetch (https://universal-demo.ereckgordon.com/ngsw-worker.js:2464:37)
    at Driver.handleFetch (https://universal-demo.ereckgordon.com/ngsw-worker.js:1975:25)
    at <anonymous>) Driver.fetch(https://universal-demo.ereckgordon.com/)

here's the line that is being referenced by the error message: https://github.com/EreckGordon/angular-universal-pwa-starter-deploy/blob/master/dist/dist-browser/ngsw-worker.js#L1975

some googling shows me some other people that seem to have solved their issue in their own respective projects:

thgh/sapper-template@cccd9b9
https://github.com/paulirish/caltrainschedule.io/pull/51/files

@alxhub

@tkohr
Copy link

tkohr commented Mar 1, 2018

I have also run into the same problem (https://stackoverflow.com/questions/48828413/angular-service-worker-failed-to-load-resource-the-server-responded-with-a-st).

In my case the error is triggered by the "request"/URL that initializes of my Angular 5 app (using hash style URLs, like: https://example.com/nightly/#/connect). As the part behind the # should usually never be sent to the server, I am surprised to find the (entire) URL in the fetch event of the service worker.

There, the request has the following data:

request

So according to the error message, the attributes "cache" and "mode" generated by my Angular app (HashLocationStrategy) are conflicting with the service worker fetch implementation of Chrome v64.

I see 3 options here:

a) Prevent Angular to send the init URL of its application (https://example.com/nightly/#/connect) to the service worker
=> I do not know if such a thing is possible or if the browser handles this completely.

b) Prevent the service worker to do a fetch for the init URL of the Angular app
=> a condition such as https://github.com/paulirish/caltrainschedule.io/pull/51/files would do the trick
=> Would this be a proper solution?

c) Manipulate the attributes "cache" or "mode" either in the Angular app or the service worker to values not conflicting with Chrome v64.
=> I guess this is not the right approach, as the attributes are read-only (https://developer.mozilla.org/en-US/docs/Web/API/Request/mode)

@EreckGordon & @chamikasandamal : Which are the URLs that trigger the error on your side?

@EreckGordon
Copy link

It seems to trigger for me on any url, only the first time opening dev tools while viewing the site. If you close the tab, then reopen the site and reopen dev tools the error appears again.

I don't use hash routing. Here's a site demonstrating the issue:

https://universal-demo.ereckgordon.com/

gkalpak added a commit to gkalpak/angular that referenced this issue Mar 20, 2018
Under some circumstances (possibly related to opening Chrome DevTools),
requests are made with `cache: 'only-if-cached'` and `mode: 'no-cors'`.
These request will eventually fail, because `only-if-cached` is only
allowed to be used with `mode: 'same-origin'`.
This is likely a bug in Chrome DevTools.

This commit avoids errors related to such requests by not handling them.

Fixes angular#22362
gkalpak added a commit to gkalpak/angular that referenced this issue Mar 23, 2018
Under some circumstances (possibly related to opening Chrome DevTools),
requests are made with `cache: 'only-if-cached'` and `mode: 'no-cors'`.
These request will eventually fail, because `only-if-cached` is only
allowed to be used with `mode: 'same-origin'`.
This is likely a bug in Chrome DevTools.

This commit avoids errors related to such requests by not handling them.

Fixes angular#22362
gkalpak added a commit to gkalpak/angular that referenced this issue Mar 23, 2018
Under some circumstances (possibly related to opening Chrome DevTools),
requests are made with `cache: 'only-if-cached'` and `mode: 'no-cors'`.
These request will eventually fail, because `only-if-cached` is only
allowed to be used with `mode: 'same-origin'`.
This is likely a bug in Chrome DevTools.

This commit avoids errors related to such requests by not handling them.

Fixes angular#22362
@akilmakda
Copy link

I have also run into the same problem but in my case in local server http-server -p 8000 all images load. but when i upload dist folder to server first time load all images after soft refresh only https images load but http images not load. (when images load form service worker that time issue occurred).

After hard refresh (Ctrl + Shift + r) all images load.

why angular service worker not load http images?

thanks in advance.

@gkalpak
Copy link
Member

gkalpak commented Mar 26, 2018

@akilmakda, this sounds like a different issue. If you think it is related to @angular/service-worker, please open a new issue and provide all relevant details (including a minimal reproduction).

@akilmakda
Copy link

akilmakda commented Mar 26, 2018

@gkalpak
Copy link
Member

gkalpak commented Mar 26, 2018

@akilmakda, the error message (which comes from the browser, not @angular/service-worker) explains why it is failing. I don't think this is related to Angular's ServiceWorker.

(In any case, this issue is not the place to discuss unrelated problems. If you still think there is an issue with @angular/service-worker please open a new isue.)

@akilmakda
Copy link

Create new issue #23012

@alxhub alxhub closed this as completed in d9dc46e Mar 28, 2018
alxhub pushed a commit that referenced this issue Mar 28, 2018
Under some circumstances (possibly related to opening Chrome DevTools),
requests are made with `cache: 'only-if-cached'` and `mode: 'no-cors'`.
These request will eventually fail, because `only-if-cached` is only
allowed to be used with `mode: 'same-origin'`.
This is likely a bug in Chrome DevTools.

This commit avoids errors related to such requests by not handling them.

Fixes #22362

PR Close #22883
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: service-worker Issues related to the @angular/service-worker package type: bug/fix
Projects
None yet
Development

No branches or pull requests

6 participants