Restore SIGINT force-exit and rename shutdown flag

This commit is contained in:
Marcelo Trylesinski 2026-04-02 15:28:38 -04:00
parent c86c701254
commit e8b99bcb4a
4 changed files with 14 additions and 11 deletions

View File

@ -309,4 +309,7 @@ def test_handle_exit_sets_force_exit_on_second_signal(unused_tcp_port: int):
assert server.force_exit is False
server.handle_exit(sig=signal.SIGTERM, frame=None)
assert server.force_exit is False
server.handle_exit(sig=signal.SIGINT, frame=None)
assert server.force_exit is True

View File

@ -342,7 +342,7 @@ class H11Protocol(asyncio.Protocol):
self.transport.close()
else:
self.cycle.keep_alive = False
self.cycle.disconnect_on_shutdown = True
self.cycle.shutting_down = True
self.cycle.message_event.set()
def abort(self) -> None:
@ -398,7 +398,7 @@ class RequestResponseCycle:
# Connection state
self.disconnected = False
self.disconnect_on_shutdown = False
self.shutting_down = False
self.keep_alive = True
self.waiting_for_100_continue = conn.they_are_waiting_for_100_continue
@ -433,7 +433,7 @@ class RequestResponseCycle:
self.logger.error(msg)
await self.send_500_response()
elif not self.response_complete and not self.disconnected:
if not self.disconnect_on_shutdown:
if not self.shutting_down:
msg = "ASGI callable returned without completing response."
self.logger.error(msg)
self.transport.close()
@ -540,12 +540,12 @@ class RequestResponseCycle:
self.transport.write(output)
self.waiting_for_100_continue = False
if not self.disconnected and not self.response_complete and not self.disconnect_on_shutdown:
if not self.disconnected and not self.response_complete and not self.shutting_down:
self.flow.resume_reading()
await self.message_event.wait()
self.message_event.clear()
if self.disconnected or self.response_complete or self.disconnect_on_shutdown:
if self.disconnected or self.response_complete or self.shutting_down:
return {"type": "http.disconnect"}
message: HTTPRequestEvent = {

View File

@ -348,7 +348,7 @@ class HttpToolsProtocol(asyncio.Protocol):
self.transport.close()
else:
self.cycle.keep_alive = False
self.cycle.disconnect_on_shutdown = True
self.cycle.shutting_down = True
self.cycle.message_event.set()
def abort(self) -> None:
@ -402,7 +402,7 @@ class RequestResponseCycle:
# Connection state
self.disconnected = False
self.disconnect_on_shutdown = False
self.shutting_down = False
self.keep_alive = keep_alive
self.waiting_for_100_continue = expect_100_continue
@ -439,7 +439,7 @@ class RequestResponseCycle:
self.logger.error(msg)
await self.send_500_response()
elif not self.response_complete and not self.disconnected:
if not self.disconnect_on_shutdown:
if not self.shutting_down:
msg = "ASGI callable returned without completing response."
self.logger.error(msg)
self.transport.close()
@ -572,12 +572,12 @@ class RequestResponseCycle:
self.transport.write(b"HTTP/1.1 100 Continue\r\n\r\n")
self.waiting_for_100_continue = False
if not self.disconnected and not self.response_complete and not self.disconnect_on_shutdown:
if not self.disconnected and not self.response_complete and not self.shutting_down:
self.flow.resume_reading()
await self.message_event.wait()
self.message_event.clear()
if self.disconnected or self.response_complete or self.disconnect_on_shutdown:
if self.disconnected or self.response_complete or self.shutting_down:
return {"type": "http.disconnect"}
message: HTTPRequestEvent = {"type": "http.request", "body": self.body, "more_body": self.more_body}
self.body = b""

View File

@ -348,7 +348,7 @@ class Server:
def handle_exit(self, sig: int, frame: FrameType | None) -> None:
self._captured_signals.append(sig)
if self.should_exit:
if self.should_exit and sig == signal.SIGINT:
self.force_exit = True # pragma: full coverage
else:
self.should_exit = True