When running aiohttp.web with gunicorn in python 3.8, every request results in a reset connection.
This behavior does not occur using Flask, therefore I believe it is aiohttp's fault, not gunicorn's.
from aiohttp import web
app = web.Application()
routes = web.RouteTableDef()
@routes.get('/')
async def index(request):
return 'Hello, world!'
app.add_routes(routes)
gunicorn --worker-class aiohttp.GunicornWebWorker app:app &
curl http://localhost:8000/
Hello, world!
curl: (52) Empty reply from server
In a browser, I get "the connection was reset".
aiohttp v3.6.2
gunicorn v19.9.0
CPython v3.8.0
Arch Linux, kernel version 5.3.7-arch1-2-ARCH
aiohttp.web
You should return a web.Response in handler, not plain text.
from aiohttp import web
app = web.Application()
routes = web.RouteTableDef()
@routes.get('/')
async def index(request):
return web.Response(text="Hello, world!")
app.add_routes(routes)
gunicorn --worker-class aiohttp.GunicornWebWorker app:app
curl http://localhost:8000/
You're right, in my example code, I missed that part. However, I have it in my production code and I am getting the same error. I'm not sure how to reproduce this minimally.
https://github.com/EmoteCollector/EmoteCollector-website/blob/master/app.py
Running this with gunicorn in 3.8 gives me the issues in question.
https://github.com/EmoteCollector/EmoteCollector-website/blob/master/app.py
Running this with gunicorn in 3.8 gives me the issues in question.
Can you describe it in more details? Have you this issue in all handlers in your application?
All handlers, yes. I added a handler that just returns web.Response(text='hi') and I still get the error. I added a handler that just returns 'hi' (incorrectly) and I get the same error.
Works for me in Python 3.8.0, Ubuntu 18.04
from aiohttp import web
import gunicorn
import aiohttp
import sys
app = web.Application()
routes = web.RouteTableDef()
@routes.get('/')
async def index(request):
v = sys.version
aiohttp_v = aiohttp.__version__
gunicorn_v = gunicorn.__version__
return web.Response(text=f"Hello, world!\nPython Version: {v}\nAIOHTTP Version: {aiohttp_v}\nGunicorn Version: {gunicorn_v}\n")
app.add_routes(routes)
# $ gunicorn --worker-class aiohttp.GunicornWebWorker app:app
$ curl 127.0.0.1:8000
Hello, world!
Python Version: 3.8.0 (default, Oct 14 2019, 21:29:03)
[GCC 7.4.0]
AIOHTTP Version: 3.6.2
Gunicorn Version: 19.9.0
OK, I've made the test case as minimal as I could, but it's still pretty heavy.
You'll need postgres.
git clone --single-branch --branch add-test-route https://owo.codes/lambda/cm-api.git
cd cm-api
python3.8 -m venv .venv
source .venv/bin/activate
pip install -Ur requirements.txt
cp config.example.json5 config.json5
sed -i "s|discord: ''|discord: 'NjE4NTU0NzEwNTk2NjQ4OTgw.XW7X_A.oBMlTi_8WGGTYpjLgCJ-tbKMuZ4'|" config.json5
createdb cm
./start.sh &
curl http://localhost:8081/api/v0/test
I get curl: (56) Recv failure: Connection reset by peer following these steps.
Okay, i have same issue. I think it's a gunicorn (or your application) problem, because plain app works pretty.
How should I fix it?
Give me a few time, i'll try to deal with it.
LOL, i found a really comical bug (or no?). In your environment even aiohttp web server doesn't work.
from aiohttp import web
import gunicorn
import aiohttp
import sys
app = web.Application()
routes = web.RouteTableDef()
@routes.get('/')
async def index(request):
v = sys.version
aiohttp_v = aiohttp.__version__
gunicorn_v = gunicorn.__version__
return web.Response(text=f"Hello, world!\nPython Version: {v}\nAIOHTTP Version: {aiohttp_v}\nGunicorn Version: {gunicorn_v}\n")
app.add_routes(routes)
web.run_app(app)
curl http://127.0.0.1:8080
curl: (56) Recv failure: Connection reset by peer
I really don't know why it's. May do you know @iomintz ?
Yes, I get the same in that environment. I'm not sure why it is either.
Ah, discord.py depends on an old version of aiohttp, one which appears to be incompatible with 3.8 when used in this way.
¯_(ツ)_/¯
Most helpful comment
Give me a few time, i'll try to deal with it.