sanic
sanic copied to clipboard
Sanic raising 503 before timeout period exhausted
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
I don't know, after setting these, it will still report the same error
sanic 22.3.0 use ASGI
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
I just traverse the list and send requests to other servers
![image](https://user-images.githubusercontent.com/73318286/162564946-e13696a9-4efa-451e-b2d8-615971eeb482.png)
When I stay in the task for too long, sanic will automatically explode 503 730 errors
![image](https://user-images.githubusercontent.com/73318286/162566906-ccf117c6-f381-4f38-a0ba-77690842e560.png)
![image](https://user-images.githubusercontent.com/73318286/162566959-dcaa6cae-7f03-4fa1-8024-cfd24b88b4ca.png)
![image](https://user-images.githubusercontent.com/73318286/162566972-bd3c19b0-925d-47c7-ae02-af88feb9ba00.png)
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
![image](https://user-images.githubusercontent.com/73318286/162567083-e559c925-dea3-4eab-b0eb-e7280e0a0f33.png)
A couple of things I can notice:
- Try using
aiohttp
orhttpx
instead ofrequests
if you can.requests
is blocking, and it makes async pretty much useless 😉. - 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 toapp.ctx
and then read it from there by usingrequest.app.ctx
. Note that this will only work if the file's contents is static/doesn't change. - You can run the app by simply doing
app.run(...)
. No need to doasyncio.run(app.run(...))
. - 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.
solved. But I changed the asynchronous to not asynchronous and solved it. But it looks weird
Glad to hear! I’ll leave this open so @ahopkins can clarify on the 503 when he’s around :)
Is this an issue? Closing. If there is an issue please open and provide me with some copy/pastable code to replicate.