ameer b8e29e9b1e fix(room): widen WS handler exception scope to JSONDecodeError + RuntimeError
A single malformed JSON message (or a "WebSocket is not connected" race
on disconnect) was killing the per-client handler with an uncaught
exception in the ASGI app. The surrounding try/except only caught
WebSocketDisconnect, so the server would log a stack trace and the
client would silently drop.

Wrap receive_json() to catch JSONDecodeError, send a structured
{"type":"error","code":"bad_message"} ack, and continue. Widen the
outer except to (WebSocketDisconnect, RuntimeError) so disconnect
races on send/receive after close exit the handler cleanly instead
of bubbling up the ASGI stack.

Both student_ws and instructor_ws hardened in parallel. 31/31 pytest
suite still passes; this fixes the recurring fuzz-scenario warn and
the cycle-187-style cascade observed in the stress loop.
2026-05-02 17:31:25 +08:00
2026-05-02 03:02:08 +08:00
2026-05-02 02:54:34 +08:00
2026-05-02 02:52:43 +08:00
2026-05-02 02:54:34 +08:00

Live In-Lecture Quiz Portal

FastAPI, SQLite, WebSocket, and vanilla frontend implementation for a live classroom quiz.

Install

cd /home/ameer/RD/Projects/Apps/quiz
python3 -m venv .venv
. .venv/bin/activate
pip install -e '.[dev]'
cp .env.example .env

Edit .env and set real values for QUIZ_SECRET_KEY and QUIZ_ADMIN_PASSWORD.

Run

. .venv/bin/activate
uvicorn app.main:app --host 127.0.0.1 --port 8001 --reload

Open http://127.0.0.1:8001/admin/, log in, create a quiz pool, then create a session. Use the displayed join URL in another browser or private window for the student view.

Test

. .venv/bin/activate
pytest -q
pytest --cov=app

The load simulation test creates 50 student WebSocket clients and runs a 5-question quiz.

Manual Smoke Test

export QUIZ_DB_PATH=/tmp/quiz-smoke.db QUIZ_SECRET_KEY=smoke-secret QUIZ_ADMIN_PASSWORD=smoke-pass QUIZ_PUBLIC_URL=http://127.0.0.1:8001
. .venv/bin/activate
uvicorn app.main:app --host 127.0.0.1 --port 8001
curl http://127.0.0.1:8001/healthz

Expected health response starts with {"ok":true.

Description
No description provided
Readme 226 KiB
Languages
Python 43.7%
JavaScript 33%
CSS 19.3%
Shell 3.1%
Smarty 0.6%
Other 0.3%