fix: handle RuntimeError in notification_manager emit()

asyncio.get_running_loop() raises RuntimeError when emit() is called
from a thread without an active event loop (e.g. when the disk space
check in project_manager triggers a log.warning notification from a
threadpool worker).

This causes a 500 Internal Server Error on project creation/open when
disk usage is high, instead of the intended warning notification.

Wrap the emit loop in try/except RuntimeError so that notifications
are silently dropped when no event loop is available, rather than
crashing the request.

Fixes #2502
Fixes #2505
This commit is contained in:
Dale Arbogast 2026-02-19 16:49:50 -05:00
parent 013ec341b3
commit 279f05a14a

View File

@ -53,8 +53,13 @@ class NotificationManager:
:param kwargs: Add this meta to the notification (project_id for example)
"""
for listener in self._listeners:
asyncio.get_running_loop().call_soon_threadsafe(listener.put_nowait, (action, event, kwargs))
try:
for listener in self._listeners:
asyncio.get_running_loop().call_soon_threadsafe(listener.put_nowait, (action, event, kwargs))
except RuntimeError:
# asyncio.get_running_loop() raises RuntimeError when called from
# a threadpool with no active event loop (e.g. disk space warnings)
pass
@staticmethod
def reset():