aiohttp server hangs when nginx try to mixin plain http request with failed websocket connection upgrade in one tcp stream. #3380
Closed
Description
Long story short
aiohttp server hangs when nginx try to mixin plain http request with failed websocket connection upgrade in one tcp stream.
The following tcpdump capture shows what happens in detail.
Expected behaviour
Server returns something.
Actual behaviour
Server hangs forever without closing tcp connection. Nginx return 504 Gateway timeout to end user.
Steps to reproduce
- write a simple api server using aiohttp (version 3.4.4 in my case), implement some /api/xxx for testing, leave /ws unimplemented.
- using nginx to reverse proxy to this api server.
- user open browser targeting a web page which contains both ws request and api request. Then api query will gateway timeout.
Example nginx.conf:
...
location /api/ {
proxy_pass http://server_backend;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /ws {
proxy_pass http://server_backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
aiohttp server serves /api/ request, but leave /ws unimplemented.
Then this issue could be reproduced.
Your environment
Docker: nginx:latest
Docker: aiohttp3.4.4 on python:3.7-alpine3.7

