sse-starlette doesn't seem to respect uvicorn.server.Server.config.timeout_graceful_shutdown.
From some digging, my understanding of the issue is as follows:
sse_starlette monkey patches uvicorn's signal handler
This configures a class called AppStatus, which holds an event should_exit_event
The monkey patched signal handler sets should_exit_event
When EventSourceResponse gets __call__ed, it creates an anyio task group with three tasks:
Stream the response
Ping on the connection every 15s (to avoid a behavior where proxies sometimes auto disconnect after some period of inactivity)
Wait for should_exit_event to be set
If any of these three tasks exit (i.e. streaming the response finishes, pinging fails, the exit signal handler is triggered), all three tasks get immediately canceled.
The problem is specifically that if should_exit_event is set, then the tasks are immediately canceled without respecting uvicorn.server.Server.config.timeout_graceful_shutdown.
Possible solutions
Add some asyncio.sleep in AppStatus.handle_exit and possibly a similar force_exit mechanism to Uvicorn to handle receiving multiple signals
Issue
sse-starlette
doesn't seem to respectuvicorn.server.Server.config.timeout_graceful_shutdown
.From some digging, my understanding of the issue is as follows:
AppStatus
, which holds an eventshould_exit_event
should_exit_event
__call__
ed, it creates ananyio
task group with three tasks:should_exit_event
to be setThe problem is specifically that if
should_exit_event
is set, then the tasks are immediately canceled without respectinguvicorn.server.Server.config.timeout_graceful_shutdown
.Possible solutions
asyncio.sleep
inAppStatus.handle_exit
and possibly a similarforce_exit
mechanism toUvicorn
to handle receiving multiple signals