master
.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).
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)
A response is printed.
Uvicorn doesn't serve a response
Running uvicorn 0.15.0 with CPython 3.9.5 on Darwin
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too