Skip to content

aiohttp server hangs when nginx try to mixin plain http request with failed websocket connection upgrade in one tcp stream. #3380

Closed
@zTrix

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.

deepinscreenshot_select-area_20181105120935

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

  1. write a simple api server using aiohttp (version 3.4.4 in my case), implement some /api/xxx for testing, leave /ws unimplemented.
  2. using nginx to reverse proxy to this api server.
  3. user open browser targeting a web page which contains both ws request and api request. Then api query will gateway timeout.

deepinscreenshot_select-area_20181105122712

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

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions