diff --git a/pynecone/app.py b/pynecone/app.py index b437254a7..294703a57 100644 --- a/pynecone/app.py +++ b/pynecone/app.py @@ -4,6 +4,7 @@ from typing import Any, Callable, Coroutine, Dict, List, Optional, Tuple, Type, from fastapi import FastAPI, WebSocket from fastapi.middleware import cors +from starlette.websockets import WebSocketDisconnect from pynecone import constants, utils from pynecone.base import Base @@ -320,7 +321,11 @@ def _event(app: App): # Process events until the connection is closed. while True: # Get the event. - event = Event.parse_raw(await websocket.receive_text()) + try: + event = Event.parse_raw(await websocket.receive_text()) + except WebSocketDisconnect: + # Close the connection. + return # Process the event. update = await process(app, event)