sbcl run-program hang when there is large amount of output from program

246 views Asked by At

Recently I find a run-program hang issue of sbcl 1.2.7 (32bits, linux). The code as following

(progn
  (with-open-file (s "test.out" :direction :output :if-exists :supersede)
    (loop repeat 900 do (write-line (make-string 76 :initial-element #\x) s)))
  (run-program "/bin/bash" (list "-c" "cat test.out") :output :stream))

That is when the "cat test.out" produce many lines of output to the process-output stream of process object, the `run-program' call hang forever. On my test machine, when the number of lines larger than 900, this issue happens. Otherwise just fine. I doubt this issue caused by some kind of block (maybe buffer is full?) when the output data written to the process-output stream. If we change the code as following (avoid data written to the process-output stream), the run-program call returns immediately:

(length 
  (with-output-to-string (s)
      (run-program "/bin/bash" (list "-c" "cat test.out")
                   :output s)))
;;=> 69300

I don't know whether that's a bug. Is there method by which we can make the call just return when the hang issue happens?

There is also a similar question: how-to-read-from-large-process-output-correctly , but I don't get the answer why the run-program call hang there.

1

There are 1 answers

1
Frank Zalkow On BEST ANSWER

I also think that could be some buffer problem. However, if you read from :stream line by line, that works fine:

(let ((process
       (run-program "/bin/bash" (list "-c" "cat test.out") :output :stream :wait nil)))
  (loop for line = (read-line (process-output process) nil :eof)
        until (eq line :eof)
        do (print line)))