Skip to content

Commit 150598e

Browse files
committed
Clear _shutdown flag on server startup across all backends
After a shutdown sets _streaming._shutdown, a hot-reloaded restart in the same process keeps it set, so all new streams exit immediately and the page shows connection errors. Clear it on startup in each backend: lifespan.startup for FastAPI, run() for Quart and Flask.
1 parent 9fa8ce4 commit 150598e

3 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎dash/backends/_fastapi.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
STREAM_HEADERS,
4141
STREAM_MIMETYPE,
4242
StreamedCallbackResponse,
43+
_shutdown as _streaming_shutdown,
4344
keepalive_seconds,
4445
marker_ndjson_aiter,
4546
to_json,
@@ -248,7 +249,9 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
248249

249250
async def _receive_with_shutdown():
250251
msg = await receive()
251-
if msg.get("type") == "lifespan.shutdown":
252+
if msg.get("type") == "lifespan.startup":
253+
_streaming_shutdown.clear()
254+
elif msg.get("type") == "lifespan.shutdown":
252255
shutdown_active_streams()
253256
return msg
254257

‎dash/backends/_flask.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
STREAM_HEADERS,
4141
STREAM_MIMETYPE,
4242
StreamedCallbackResponse,
43+
_shutdown as _streaming_shutdown,
4344
andjson_lines,
4445
keepalive_seconds,
4546
ndjson_lines,
@@ -184,6 +185,7 @@ def has_request_context(self) -> bool:
184185
return has_request_context()
185186

186187
def run(self, dash_app: Dash, host: str, port: int, debug: bool, **kwargs: Any):
188+
_streaming_shutdown.clear()
187189
self.server.run(host=host, port=port, debug=debug, **kwargs)
188190

189191
def make_response(

‎dash/backends/_quart.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
STREAM_HEADERS,
4545
STREAM_MIMETYPE,
4646
StreamedCallbackResponse,
47+
_shutdown as _streaming_shutdown,
4748
keepalive_seconds,
4849
marker_ndjson_aiter,
4950
to_json,
@@ -298,6 +299,7 @@ def run(self, dash_app: Dash, host: str, port: int, debug: bool, **kwargs: _t.An
298299

299300
loop = asyncio.new_event_loop()
300301
asyncio.set_event_loop(loop)
302+
_streaming_shutdown.clear()
301303

302304
# Initialize shutdown event for WebSocket handlers
303305
self._ws_shutdown_event = asyncio.Event()

0 commit comments

Comments
 (0)