Commit Graph

5 Commits

Author SHA1 Message Date
RUiNtheExtinct
1a410446e3 fix(logger): add max size limit for pending logs to prevent OOM
If flush callbacks persistently fail (e.g., network issues), logs would
accumulate indefinitely in _logs_since_flush, potentially causing OOM
on long-running servers.

Added MAX_PENDING_LOGS (10000) limit - when exceeded, oldest logs are
dropped. This is similar to how the global logs deque uses maxlen.
2025-12-28 14:35:31 +05:30
RUiNtheExtinct
494dce9a36 fix(logger): preserve logs for retry when callback raises exception
Move log clearing to after all callbacks succeed, not before. This
ensures that if any callback raises an exception, the logs remain
available for retry on the next flush call instead of being lost.

The previous approach cleared logs before iterating callbacks,
which meant logs were permanently lost if any callback failed.
2025-12-28 13:49:09 +05:30
RUiNtheExtinct
ddad64a4bf fix(logger): prevent duplicate logs when callback raises exception
Clear _logs_since_flush before iterating callbacks by capturing logs
into a local variable first. This prevents duplicate logs if a
callback raises an exception, since the instance variable is already
cleared before any callback runs.

Add test to verify logs are cleared even when callbacks raise.
2025-12-28 13:36:59 +05:30
RUiNtheExtinct
c06b18a014 fix(logger): clear logs after all callbacks, not inside loop
Move _logs_since_flush reset outside the callback loop so all
registered callbacks receive the same log data instead of only
the first callback getting logs while subsequent ones get an empty list.

Add test to verify multiple callbacks all receive the same logs.
2025-12-28 13:31:45 +05:30
RUiNtheExtinct
e86ffb0ea6 fix(logger): handle OSError errno 22 on flush for Windows piped streams
When running ComfyUI in API mode on Windows, print() statements from
custom nodes can crash with "OSError: [Errno 22] Invalid argument"
during flush. This occurs because piped/redirected stdout streams on
Windows may fail to flush even after successful writes.

This fix catches OSError with errno 22 (EINVAL) specifically in
LogInterceptor.flush(), allowing the flush callbacks to still execute.
The error is safe to ignore since write() already succeeded.

Fixes #11367
2025-12-28 13:29:27 +05:30