craftql icon indicating copy to clipboard operation
craftql copied to clipboard

503 Service Unavailable

Open Jones-S opened this issue 6 years ago • 4 comments

Hi there. Another issue by me. So sorry about it 🙏🏼

Now that I bought the plugin and deployed the live site, graphql just returns random 503 Service Unavailable errors...

Does anyone have a clue why? It never happened before (except due to some strange behaviour in my other issue (#307).

And now it starts happening on the live page, just for some requests via apollo and even when building the page from netlify:

Screenshot 2019-09-15 at 13 19 11

The only thing that has changed, is that my live page still is waiting for the SSL the be provisioned, but that's about it. I doubt that the server is down every few requests too...

Maybe it has to do with CORS issues again: image

And also: Failed to load resource: Origin http://www.live-site.ch is not allowed by Access-Control-Allow-Origin.

I do have a config/craftql.php file where I have stated:

'allowedOrigins' => [
      '*'
    ]

So it should actually be allowed...

I really don't know where this could originate from... Any hint would be very welcome...

Error logs from Server: You can see every now and then there is a 503. 🤷‍♂️

80....IP...40 - - [15/Sep/2019:13:48:16 +0200] "POST /api HTTP/1.1" 503 26992 "-" "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"
80....IP...40 - - [15/Sep/2019:13:48:16 +0200] "POST /api HTTP/1.1" 200 2758 "-" "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"
80....IP...40 - - [15/Sep/2019:13:48:16 +0200] "POST /api HTTP/1.1" 200 1049 "-" "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"
80....IP...40 - - [15/Sep/2019:13:48:16 +0200] "POST /api HTTP/1.1" 200 3239 "-" "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"
80....IP...40 - - [15/Sep/2019:13:48:16 +0200] "POST /api HTTP/1.1" 200 3423 "-" "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"
80....IP...40 - - [15/Sep/2019:13:48:16 +0200] "POST /api HTTP/1.1" 200 3247 "-" "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"
80....IP...40 - - [15/Sep/2019:13:48:16 +0200] "POST /api HTTP/1.1" 200 3459 "-" "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"
80....IP...40 - - [15/Sep/2019:13:48:16 +0200] "POST /api HTTP/1.1" 200 1937 "-" "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"
80....IP...40 - - [15/Sep/2019:13:48:16 +0200] "POST /api HTTP/1.1" 200 3459 "-" "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"
80....IP...40 - - [15/Sep/2019:13:48:16 +0200] "POST /api HTTP/1.1" 200 5858 "-" "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"
80....IP...40 - - [15/Sep/2019:13:48:16 +0200] "POST /api HTTP/1.1" 503 26992 "-" "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"
80....IP...40 - - [15/Sep/2019:13:48:16 +0200] "POST /api HTTP/1.1" 503 26992 "-" "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"
80....IP...40 - - [15/Sep/2019:13:48:16 +0200] "POST /api HTTP/1.1" 503 26992 "-" "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"
80....IP...40 - - [15/Sep/2019:13:48:16 +0200] "POST /api HTTP/1.1" 200 5858 "-" "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"

... 🤔 could it be that the request times out? All 503 errors have a number next to them: 26992 Is this the time for the request in milliseconds?

Jones-S avatar Sep 15 '19 11:09 Jones-S

Jonas, this as with many things in modern development probably means you'll need to exercise your Google-fu...

Here on a Sunday are a couple of items that look like they might hint at CORS specifics that can happen with Netlify:

  • https://community.netlify.com/t/how-handle-cors-error-in-netlify/2721 (see particularly right at the end)
  • https://alligator.io/nodejs/solve-cors-once-and-for-all-netlify-dev/

I don't think it's timeouts -- 503 is a hard refusal from the server, as you can also look up.

narration-sd avatar Sep 15 '19 20:09 narration-sd

p.s. good if you post what you find actually solves this, nice for others to find

narration-sd avatar Sep 15 '19 20:09 narration-sd

Actually I did find a solution – at least it made the error go away:

I thought – because of the suspicion that the timeout was a problem – that I could just redo the apollo call. So I used: https://www.apollographql.com/docs/link/links/retry/

This means if the request fails it will just redo it. This got all my netlify builds go through smoothly and I resolved weird errors within the running app.

I am still not sure, if it was a timeout thing, and maybe my retry.stuff is just covering the underlying problem. I will try to investigate more, but for now I am just glad I got the project up and running again.

Thank you very much for your quick responses. I really appreciate this! I hope some of my numerous questions maybe help somebody else one day. I will try to up my google-game ;). Weirdly it only appeared after the project went life and we had a pre-version online on netlify for almost 2 weeks and I never experienced this error before...

Jones-S avatar Sep 16 '19 22:09 Jones-S

Oh hey: this could be it:

Second of all, this problem is happening because you’re hitting an https:// API from http://localhost, which doesn’t have SSL, so the problem could go away once you deploy onto an https enabled domain

from https://alligator.io/nodejs/solve-cors-once-and-for-all-netlify-dev/

I was still waitint for the certificate to be provisioned (because there was an additional AAAA record I forgot to delete). During that time the domain was still http requesting the API.

What to me still does not make sense, is, why a netlify build would be influenced by the domain, where the live page is shown. I mean is my request during a build a different one, if the page that is deployed is using the http protocol, than if the deployed page is using https? 🤷‍♂️ (Also when calling the API from http://localhost:3000 it always worked like a charm, so I did not think of an SSL problem...)

Anyway, as I said I will keep investigating.

Jones-S avatar Sep 16 '19 22:09 Jones-S