sanic icon indicating copy to clipboard operation
sanic copied to clipboard

Sanic raising 503 before timeout period exhausted

Open Charles-Hello opened this issue 2 years ago • 12 comments

8|sanicgame | 2022-04-06T09:46:43: [2022-04-06 09:46:43 +0000] - (sanic.access)[INFO][192.168.1.50:62892]: POST http://192.168.1.145:8888/robot/wx 503 730 image

Charles-Hello avatar Apr 06 '22 09:04 Charles-Hello

I don't know, after setting these, it will still report the same error

Charles-Hello avatar Apr 06 '22 09:04 Charles-Hello

sanic 22.3.0 use ASGI

Charles-Hello avatar Apr 06 '22 09:04 Charles-Hello

How are you making this request? Using cURL or similar? Can you post the command you're using and a small code snippet that this can be reproduced with?

prryplatypus avatar Apr 08 '22 11:04 prryplatypus

@prryplatypus image I just traverse the list and send requests to other servers

image

Charles-Hello avatar Apr 09 '22 09:04 Charles-Hello

When I stay in the task for too long, sanic will automatically explode 503 730 errors

Charles-Hello avatar Apr 09 '22 09:04 Charles-Hello

image What is the specific reason? ? Is it my bad asynchronous writing or is it a problem with sanic?

Charles-Hello avatar Apr 09 '22 09:04 Charles-Hello

image image

Charles-Hello avatar Apr 09 '22 09:04 Charles-Hello

I have set the value of RESPONSE_TIMEOUT to 60 according to the error report, but the server will still stop the task. When my await asyncio.sleep(30), the sanic server will not even execute the function below, and the terminal will explode 503 directly. , the error of 730

Charles-Hello avatar Apr 09 '22 10:04 Charles-Hello

image Just like this, after five or six seconds, the server will not automatically explode 503 and 730 errors

Charles-Hello avatar Apr 09 '22 10:04 Charles-Hello

A couple of things I can notice:

  1. Try using aiohttp or httpx instead of requests if you can. requests is blocking, and it makes async pretty much useless 😉.
  2. Opening files is also a blocking operation. Instead of doing with open(...) on each request, you might want to load the files once during application startup, save it to app.ctx and then read it from there by using request.app.ctx. Note that this will only work if the file's contents is static/doesn't change.
  3. You can run the app by simply doing app.run(...). No need to do asyncio.run(app.run(...)).
  4. If sending those requests takes some time, you might want to make use of signals, so that you can respond to the request but keep that task running in the background.

As to why the request is timing out before the amount of time you configure, I am unsure why that could be happening. Maybe one of the other devs can help us out.

In the meantime, would you give those steps above a try and let us know if they work?

Best, @prryplatypus.

prryplatypus avatar Apr 09 '22 18:04 prryplatypus

solved. But I changed the asynchronous to not asynchronous and solved it. But it looks weird

Charles-Hello avatar Apr 10 '22 07:04 Charles-Hello

Glad to hear! I’ll leave this open so @ahopkins can clarify on the 503 when he’s around :)

prryplatypus avatar Apr 10 '22 12:04 prryplatypus

Is this an issue? Closing. If there is an issue please open and provide me with some copy/pastable code to replicate.

ahopkins avatar Aug 28 '22 07:08 ahopkins