Skip to content

Commit

Permalink
Merge branch 'feature/timeout_worker_is_alive' of github.com:socrates…
Browse files Browse the repository at this point in the history
…lee/uvicorn into feature/timeout_worker_is_alive
  • Loading branch information
socrateslee committed Aug 1, 2024
2 parents f1873bc + 5142aea commit ea7ecc6
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## 0.30.4 (2024-07-31)

### Fixed

- Close connection when `h11` sets client state to `MUST_CLOSE` (#2375)

## 0.30.3 (2024-07-20)

### Fixed
Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ description = "The lightning-fast ASGI server."
readme = "README.md"
license = "BSD-3-Clause"
requires-python = ">=3.8"
authors = [{ name = "Tom Christie", email = "[email protected]" }]
authors = [
{ name = "Tom Christie", email = "[email protected]" },
{ name = "Marcelo Trylesinski", email = "[email protected]" }
]
classifiers = [
"Development Status :: 4 - Beta",
"Environment :: Web Environment",
Expand Down
28 changes: 28 additions & 0 deletions tests/protocols/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@

CONNECTION_CLOSE_REQUEST = b"\r\n".join([b"GET / HTTP/1.1", b"Host: example.org", b"Connection: close", b"", b""])

REQUEST_AFTER_CONNECTION_CLOSE = b"\r\n".join(
[
b"GET / HTTP/1.1",
b"Host: example.org",
b"Connection: close",
b"",
b"",
b"GET / HTTP/1.1",
b"Host: example.org",
b"",
b"",
]
)

LARGE_POST_REQUEST = b"\r\n".join(
[
b"POST / HTTP/1.1",
Expand Down Expand Up @@ -983,6 +997,20 @@ async def test_return_close_header(http_protocol_cls: HTTPProtocol):
assert b"connection: close" in protocol.transport.buffer.lower()


async def test_close_connection_with_multiple_requests(http_protocol_cls: HTTPProtocol):
app = Response("Hello, world", media_type="text/plain")

protocol = get_connected_protocol(app, http_protocol_cls)
protocol.data_received(REQUEST_AFTER_CONNECTION_CLOSE)
await protocol.loop.run_one()
assert b"HTTP/1.1 200 OK" in protocol.transport.buffer
assert b"content-type: text/plain" in protocol.transport.buffer
assert b"content-length: 12" in protocol.transport.buffer
# NOTE: We need to use `.lower()` because H11 implementation doesn't allow Uvicorn
# to lowercase them. See: https://github.com/python-hyper/h11/issues/156
assert b"connection: close" in protocol.transport.buffer.lower()


async def test_iterator_headers(http_protocol_cls: HTTPProtocol):
async def app(scope: Scope, receive: ASGIReceiveCallable, send: ASGISendCallable):
headers = iter([(b"x-test-header", b"test value")])
Expand Down
2 changes: 1 addition & 1 deletion uvicorn/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from uvicorn.config import Config
from uvicorn.main import Server, main, run

__version__ = "0.30.3"
__version__ = "0.30.4"
__all__ = ["main", "run", "Config", "Server"]
2 changes: 2 additions & 0 deletions uvicorn/protocols/http/h11_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ def handle_events(self) -> None:
self.transport.resume_reading()
self.conn.start_next_cycle()
continue
if self.conn.their_state == h11.MUST_CLOSE:
break
self.cycle.more_body = False
self.cycle.message_event.set()

Expand Down
2 changes: 1 addition & 1 deletion uvicorn/supervisors/multiprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def target(self, sockets: list[socket] | None = None) -> Any: # pragma: no cove

def is_alive(self, timeout: float = 5) -> bool:
if not self.process.is_alive():
return False
return False # pragma: full coverage

return self.ping(timeout)

Expand Down

0 comments on commit ea7ecc6

Please sign in to comment.