Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Document RECORDING_SESSION_MAX_BYTES_PER_USER as a soft (best-effort) limit since SQLite has no row-level locks and cross-process enforcement needs Redis/Postgres advisory locks; the overrun is small and bounded by worker count

Murtaza Nasir84b4aee8c08b
diff --git a/docs/admin-guide/recording-sessions.md b/docs/admin-guide/recording-sessions.md
index 27e9cf4e..6901057c 100644
--- a/docs/admin-guide/recording-sessions.md
+++ b/docs/admin-guide/recording-sessions.md
@@ -26,7 +26,7 @@ Environment variables, all optional:
|---|---|---|
| `ENABLE_SERVER_RECORDING_CHUNKS` | `false` | Master switch. Off keeps the legacy single-shot path. |
| `RECORDING_SESSION_TTL_HOURS` | `24` | Sessions whose `last_seen_at` is older than this are reaped. |
-| `RECORDING_SESSION_MAX_BYTES_PER_USER` | `5368709120` (5 GB) | Per-user cap on in-progress (non-finalized) sessions. |
+| `RECORDING_SESSION_MAX_BYTES_PER_USER` | `5368709120` (5 GB) | Per-user cap on in-progress (non-finalized) sessions. Soft limit: concurrent chunk uploads on different sessions can overrun by up to a few chunk-sizes (16 MB each by default). Cross-process atomic enforcement would require Redis or Postgres advisory locks; the overrun is small and bounded by worker count. |
| `RECORDING_SESSION_MAX_CHUNK_BYTES` | `16777216` (16 MB) | Per-chunk upload cap. Generous; MediaRecorder chunks are typically <1 MB. |
| `RECORDING_SESSION_ALLOWED_MIME_TYPES` | `audio/webm,audio/ogg,audio/mp4,audio/mpeg,audio/wav,audio/x-m4a` | Comma-separated whitelist. |
| `RECORDING_SESSION_CLEANUP_INTERVAL_SECONDS` | `3600` | How often the background thread sweeps expired sessions. Set to `0` to disable. |
diff --git a/src/api/recording_sessions.py b/src/api/recording_sessions.py
index f4724b19..62a11c9c 100644
--- a/src/api/recording_sessions.py
+++ b/src/api/recording_sessions.py
@@ -251,6 +251,14 @@ def upload_chunk(session_id, chunk_index):
}), 413
# Per-user quota check: the new chunk must not push the user over.
+ # NOTE: this is a best-effort (soft) check. Concurrent chunks
+ # arriving on different sessions can both pass the projection and
+ # together exceed the cap by up to N * max_chunk_bytes where N is
+ # the worker count. SQLite doesn't support row-level locking, and
+ # cross-process locking would need Redis/Postgres advisory locks.
+ # The overrun is small (16 MB per concurrent chunk by default) and
+ # bounded by the session count, so we treat the quota as a
+ # soft limit and accept the race.
projected = _user_bytes_in_progress(current_user.id) - session.bytes_received + session.bytes_received + len(chunk_bytes)
if projected > _max_bytes_per_user():
return jsonify({