Skip to content

Handle half closed per HTTPWG recommendation #1264

Open
@pgjones

Description

@pgjones

Checklist

  • The bug is reproducible against the latest release and/or master.
  • There are no similar issues or pull requests to fix it yet.

Describe the bug

I've been investigating this bug report in Hypercorn and noticed that uvicorn considers half closed connections as indicating that the client is no longer interested in the response, rather than that the client has no interest in sending more. This has been recently discussed in the HTTPWG with this clarification and as I understand it Uvicorn should not act as it does. (Hypercorn follows the recommendation which partially explains the difference in the initial bug report).

To reproduce

Have Uvicorn serve,

from asyncio import CancelledError, sleep

from quart import Quart

app = Quart(__name__)

@app.route("/")
async def main():
    print("START")
    try:
        await sleep(10)
    except CancelledError:
        print("CANCELLED")
    finally:
        print("END")
    return "Hello"

and then run the following,

socket_path = ("localhost", 8000)

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(socket_path)

# Write command to socket
s.send(b"GET / HTTP/1.1\r\nhost: abcd\r\n\r\n")

# Important: Close sending direction. That way
# the other side knows we are finished.
s.shutdown(socket.SHUT_WR)

# Now read the answer
answer = s.recv(100000000)

# Parse the answer into a table (a list of lists)
table = [ line.split(b';') for line in answer.split(b'\n')[:-1] ]

print(table)

Expected behavior

A response is printed.

Actual behavior

Uvicorn doesn't serve a response

Environment

Running uvicorn 0.15.0 with CPython 3.9.5 on Darwin

Important

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions