A server started with pipes for stdout and stderr goes on running when the
process that read them exits, and a write to such a pipe fails: with
BrokenPipeError on Linux, with `OSError: [Errno 22] Invalid argument` on
Windows. The log hook of prestartup_script.py wrote to the console and
flushed it with no guard, so the failure reached whatever had printed: the
prompt of a node that prints, and of a sampler at its tqdm progress bar,
ended with that error (#3223).
The same prompts were run without the Manager. The progress bar fails there
as well, in the flush of ComfyUI's own stream, so this change covers it only
while the hook is installed (file_logging, on by default). A short print did
not fail there: the hook flushes the console after every write, which
ComfyUI's stream does not.
The two places of the logger that write to the console now go through one
method. An OSError of the console is dropped there, and the console is not
written to again: a pipe whose reader has exited and a terminal that has
hung up do not come back, and ComfyUI's stream keeps every write it could
not flush, so each further write would be kept as well. A console that fails
for a reason that can pass, as a file on a full disk, is treated the same
and gets nothing more until the server is restarted. BlockingIOError is the
exception: a console that cannot take a write right now is still there.
ValueError is left out on purpose: a write raises it for text the console
cannot encode, which is not a console that is gone, and ComfyUI's stream,
which is strict, fails that write the same way.
What is written still goes to the log file. One thing changes there while
stderr is gone: ComfyUI's own log handler fails on each record, Python's
logging reports that on sys.stderr, which is the hook, and the report, which
broke off after its first line when the console write raised, is now in the
log file in full.
The handler that copies the log records into the log file called
record.getMessage() with no guard, so a log call whose arguments do not
match its format failed its node with the exception of the format, as
TypeError, on a healthy console as well. Python's logging only reports such
a call. The call is guarded now, as it is on manager-v4, and the record goes
into the log file as a `<<logging error>>` line with the file and the line
of the call, and the error. That line does not turn the record into text
again: a message object that cannot be printed would fail there a second
time. The error is named by its type and its text, and by its type alone
when that text cannot be made either: an error can carry the message object.