opsdroid / demo-bot

⚙ Config for the opsdroid demo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Heroku keepalive is blocking the thread

jacobtomlinson opened this issue · comments

Well this is a fun little bug.

In order to keep the Heroku Dyno alive there needs to be one request every 5 minutes. Therefore I added a skill that uses match_crontab to hit the status API every 5 minutes to keep itself awake.

However, I was lazy and just used requests (not async) to make a get request. This means that when opsdroid runs the skill it blocks the event loop on the requests call which stops the web server from being able to respond to the call and eventually times out.

The fix for this is to use aiohttp to make the call or run requests in an executor.

Hooray!

2019-10-17T08:40:00.944155+00:00 heroku[router]: at=info method=GET path="/stats" host=opsdroid-demo.herokuapp.com request_id=c8c40261-7521-43ca-a8e5-a717ef59552e fwd="54.170.47.168" dyno=web.1 connect=0ms service=2ms status=200 bytes=385 protocol=https
2019-10-17T08:40:00.909364+00:00 app[web.1]: DEBUG opsdroid.parsers.crontab: Running crontab skills at Thu Oct 17 08:40:00 2019
2019-10-17T08:40:00.942703+00:00 app[web.1]: INFO aiohttp.access: 10.12.152.238 [17/Oct/2019:08:40:00 +0000] "GET /stats HTTP/1.1" 200 385 "-" "Python/3.7 aiohttp/3.6.2"