sanic-org / sanic

Accelerate your web app development | Build fast. Run fast.

Home Page:https://sanic.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sanic hangs for around 20 seconds after every 3 minutes

sham-hq opened this issue · comments

Link to code

No response

Proposal

I am using Sanic version 21.12.1 on Ubuntu 20.04.5 and below is my code to start the sanic server:

def init():
    sanic_app.run(host=HOST, port=PORT, debug=DEBUG, workers=2, access_log=False)

The issue I am facing is, after every 3 minutes, server hangs for 20 seconds and then after 20 seconds starts responding. So I started sanic with Debug True, and what I found is, before printing below line, server hangs for 20 secs, and after below line appears in log, sanic resumes responding:
Executing <Task pending name='Task-36' coro=<SignalRouter._dispatch() running at /home/ubuntu/.local/lib/python3.8/site-packages/sanic/signals.py:161> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7f5d2c2e0d60>()] created at /usr/lib/python3.8/asyncio/tasks.py:654> created at /home/ubuntu/.local/lib/python3.8/site-packages/sanic/signals.py:193> took 20.112 seconds
This is happening after every around 3 mins.
Can anybody please guide me what is this and how to solve/handle it?
Thanks

Additional context

No response

Is this a breaking change?

  • Yes

Please provide a link to your code so that we can review.

The code is in private repository, sorry can't share the link of the same. Or if you can share what specific part of code/configuration you want to see, will try to share that separately.
But I believe some background task is causing this.
And I am not being able to find out that task by Task-id Task-36.
So, if you can help me to locate same.
Thanks

Or if you can share what specific part of code/configuration you want to see, will try to share that separately.

Since we don't know your code, we can't really tell you what we'd want to see. What I can tell you is that whatever that code is likely has some blocking calls in it due to the fact that it's taking so long (~ 20 seconds) but as a background task, it should not be impacting the rest of your application.

I am guessing this is something you took over, not wrote yourself?

The code is in private repository, sorry can't share the link of the same. Or if you can share what specific part of code/configuration you want to see, will try to share that separately. But I believe some background task is causing this. And I am not being able to find out that task by Task-id Task-36. So, if you can help me to locate same. Thanks

@sham-hq Would be happy to help you, though if I've got it right you cannot share code "as is". I am seconding @sjsadowski comment on the blocking call which takes too long. Have you tried to play with number of workers ?
If you can get back with reproducible example we can figure things out.
Checkout this guide from StackOverflow for details on how to do so.