Skip to content

Commit

Permalink
Catch websocket disconnect (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
picklelo authored Dec 27, 2022
1 parent af97339 commit a93b142
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pynecone/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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
Expand Down Expand Up @@ -320,7 +321,11 @@ async def ws(websocket: WebSocket):
# 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)
Expand Down

0 comments on commit a93b142

Please sign in to comment.