mirror of
https://github.com/calibrain/shelfmark.git
synced 2026-11-16 13:18:13 +00:00
fix(websocket): release room lock before emitting progress (#1705)
Emitting progress can synchronously disconnect an expired client. Disconnect cleanup takes the same room lock held by the broadcast, deadlocking the download worker and freezing progress updates. Release the lock before emitting, as broadcast_status_update() does. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Improved handling of user-specific download progress updates when clients are connected. Administrator progress updates and the redaction of book identifiers in user updates remain unchanged. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
1 parent
f89bfd3e18
commit
02597019d5
1 file changed
+5
-3
@@ -190,9 +190,11 @@ class WebSocketManager:
|
||||
if user_id is not None:
|
||||
room = f"user_{user_id}"
|
||||
with self._rooms_lock:
|
||||
if room in self._user_rooms:
|
||||
user_data = {**data, "book_id": viewer_download_id(book_id, request_id)}
|
||||
socketio.emit("download_progress", user_data, to=room)
|
||||
has_clients = room in self._user_rooms
|
||||
# emit() can synchronously disconnect a client whose cleanup needs this lock.
|
||||
if has_clients:
|
||||
user_data = {**data, "book_id": viewer_download_id(book_id, request_id)}
|
||||
socketio.emit("download_progress", user_data, to=room)
|
||||
logger.debug("Broadcasted progress for book %s: %s%%", book_id, progress)
|
||||
except Exception:
|
||||
logger.exception("Error broadcasting download progress")
|
||||
|
||||
Reference in new issue
Block a user