@@ -128,7 +128,7 @@ public ComfyCliStreamSession execute(final ComfyCliStreamListener listener, Stri
128128
129129 private void readStdout (Process process , ComfyCliStreamListener listener , CappedBytes retained ,
130130 AtomicReference <Throwable > listenerFailure ) {
131- readLines (process .getInputStream (), new LineConsumer () {
131+ readLines (process .getInputStream (), effectiveLineLimit ( config . getMaxStdoutBytes ()), new LineConsumer () {
132132 @ Override public void accept (String line ) {
133133 retained .append ((line + "\n " ).getBytes (StandardCharsets .UTF_8 ));
134134 if (line .trim ().isEmpty ()) return ;
@@ -150,7 +150,7 @@ private void readStdout(Process process, ComfyCliStreamListener listener, Capped
150150
151151 private void readStderr (Process process , ComfyCliStreamListener listener , CappedBytes retained ,
152152 AtomicReference <Throwable > listenerFailure ) {
153- readLines (process .getErrorStream (), new LineConsumer () {
153+ readLines (process .getErrorStream (), effectiveLineLimit ( config . getMaxStderrBytes ()), new LineConsumer () {
154154 @ Override public void accept (String line ) {
155155 retained .append ((line + "\n " ).getBytes (StandardCharsets .UTF_8 ));
156156 try {
@@ -163,7 +163,7 @@ private void readStderr(Process process, ComfyCliStreamListener listener, Capped
163163 });
164164 }
165165
166- private static void readLines (InputStream input , LineConsumer consumer ) {
166+ private static void readLines (InputStream input , int maxLineBytes , LineConsumer consumer ) {
167167 ByteArrayOutputStream line = new ByteArrayOutputStream ();
168168 try {
169169 int b ;
@@ -172,7 +172,7 @@ private static void readLines(InputStream input, LineConsumer consumer) {
172172 consumer .accept (new String (line .toByteArray (), StandardCharsets .UTF_8 ));
173173 line .reset ();
174174 } else if (b != '\r' ) {
175- line .write (b );
175+ if ( line . size () < maxLineBytes ) line .write (b );
176176 }
177177 }
178178 if (line .size () > 0 ) consumer .accept (new String (line .toByteArray (), StandardCharsets .UTF_8 ));
@@ -182,6 +182,10 @@ private static void readLines(InputStream input, LineConsumer consumer) {
182182 }
183183 }
184184
185+ private static int effectiveLineLimit (int configured ) {
186+ return configured > 0 ? configured : 16 * 1024 * 1024 ;
187+ }
188+
185189 private void terminate (Process process ) {
186190 if (!process .isAlive ()) return ;
187191 process .destroy ();
0 commit comments