Comfy-Org / Comfy-Org/ComfyUI

LogInterceptor.flush() raises OSError when custom nodes or comfyui-manager wrap stdout

Open
#13,906 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
133k
Forks
15.7k
Avg merge
1d 7h
Merged PRs (30d)
158

Description

## Custom Node Testing
- [ ] I have tried disabling custom nodes and the issue persists (see [how to disable custom nodes](https://docs.comfy.org/troubleshooting/custom-node-issues#step-1%3A-test-with-all-custom-nodes-disabled) if you need help)

## Expected Behavior
Standard Python `print()` calls in custom nodes should not crash ComfyUI during startup or runtime.

## Actual Behavior
When a custom node calls `print()`, and `comfyui-manager` is installed, the stdout wrapper chain crashes with `OSError: [Errno 22] Invalid argument`. This happens because `app/logger.py`'s `LogInterceptor.flush()` calls `super().flush()` without any exception handling, and the `comfyui-manager`'s own stdout wrapper makes a nested flush call that triggers the error.

## Steps to Reproduce
1. Install ComfyUI Desktop (Windows, v0.21.1)
2. Install `comfyui-manager` (v4.2.1)
3. Install any custom node that uses bare `print()` statements, e.g. `rgthree-comfy` (has `print()` at lines 109 and 112 in `__init__.py`)
4. Start ComfyUI Desktop
5. Observe the crash: custom node fails to load with `OSError: [Errno 22] Invalid argument`
6. The workflow then fails with "Node ID #49 has no class_type" because the custom node never registered its node types

## Debug Logs
```
Traceback (most recent call last):
File "C:\Users\123\AppData\Local\Programs\ComfyUI\resources\ComfyUI\nodes.py", line 2198, in load_custom_node
module_spec.loader.exec_module(module)
File "", line 999, in exec_module
File "", line 488, in _call_with_frames_removed
File "C:\ComfyUI\custom_nodes\rgthree-comfy\__init__.py", line 109, in
print()
File "C:\ComfyUI\.venv\Lib\site-packages\comfyui_manager\prestartup_script.py", line 320, in write
self.sync_write(message)
File "C:\ComfyUI\.venv\Lib\site-packages\comfyui_manager\prestartup_script.py", line 341, in sync_write
original_stdout.flush()
File "C:\Users\123\AppData\Local\Programs\ComfyUI\resources\ComfyUI\app\logger.py", line 35, in flush
super().flush()
OSError: [Errno 22] Invalid argument
```

## Other
**ComfyUI version:** 0.21.1 (Desktop, Windows)
**comfyui-manager version:** 4.2.1
**Python:** 3.12.11

The root cause is in `app/logger.py`:
```python
def flush(self):
super().flush() # <-- should be wrapped in try/except OSError
for cb in self._flush_callbacks:
cb(self._logs_since_flush)
self._logs_since_flush = []
```

When `comfyui-manager`'s `prestartup_script.py` wraps stdout on top of `LogInterceptor`, the double-wrapping causes `super().flush()` to fail with `[Errno 22]`. Wrapping it with `try/except OSError: pass` would fix it for all custom nodes.

This is not specific to `rgthree-comfy` — any custom node that calls `print()` would trigger the same crash under the same conditions.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.