SIGINT Can't abort ASGI lifespan shutdown #2716
Unanswered
CNSeniorious000
asked this question in
Potential Issue
Replies: 2 comments
-
|
For example, this FastAPI app will hang 5 seconds and can't be skipped once started even if you keep sending SIGINT. @asynccontextmanager
async def lifespan(_):
yield
print("Shutting down...")
await sleep(5)
print("Cleaned up.")
app = FastAPI(lifespan=lifespan) |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Note that this is not directly related to #1972. I use Windows but I can't reproduce #1972 on any version of python. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Sometimes ASGI app lifespan shutdown gets stuck, and users want to use Ctrl+C to escape it. In the current logic, if two SIGINTs were received before shutdown, it will skip shutdown.
But once we've entered
await self.lifespan.shutdown()here:uvicorn/uvicorn/server.py
Lines 290 to 294 in 6d26d88
handle_exitjust keep pushing toself._captured_signalswithout further action.uvicorn/uvicorn/server.py
Lines 333 to 338 in 6d26d88
I suggest that on the third SIGINT, we call cancel on the running shutdown task or other similar approach. And then
self._captured_signalswill be flushed and a harder exit would be possible.Another approach may be checking
force_exitduring each wait inLifespanOn:And change
await self.shutdown_event.wait()intoawait self.wait(self.shutdown_event)Maybe related to:
Beta Was this translation helpful? Give feedback.
All reactions