Skip to content

Conversation

@ikeshav26
Copy link


🔄 Pull Request (Concise)

# fix: WebSocket error handling causes crashes and log pollution

## 📋 Summary
Fixes critical error handling in WebSocket streaming that causes crashes on normal disconnects and silent failures on errors.

## 🐛 Problems Fixed

**Issue 1: RuntimeError on every disconnect**
- Users stop playback → server logs `RuntimeError: Cannot call "send" once...`
- Fix: Wrap `ws.close()` in try-catch

**Issue 2: Unhandled exceptions**
- Only catches `WebSocketDisconnect`, not OOM/model errors
- Silent failures, no user feedback, resources leak
- Fix: Add generic exception handler

## 🔧 Changes

# 1. Safe WebSocket close
try:
    if ws.client_state == WebSocketState.CONNECTED:
        await ws.close()
except Exception as e:
    print(f"Error closing websocket: {e}")

# 2. Catch all streaming errors
except Exception as e:
    print(f"Error in websocket stream: {e}")
    traceback.print_exc()
    enqueue_log("backend_error", message=str(e))
    stop_signal.set()

@ikeshav26
Copy link
Author

@YaoyaoChang can u please review this PR..!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant