From e92b4bcef46330d6b7fd5ea1ed2eb607eedc1987 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Sat, 6 Jun 2020 14:38:41 -0400 Subject: [PATCH] fix(unix): do not starve subprocess that writes on stderr --- src/unix/CCUnix.ml | 10 ++++++++-- src/unix/dune | 3 +-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/unix/CCUnix.ml b/src/unix/CCUnix.ml index c3c10352..d302b87c 100644 --- a/src/unix/CCUnix.ml +++ b/src/unix/CCUnix.ml @@ -97,10 +97,16 @@ let call_full_inner ?(bufsize=2048) ?(stdin=`Str "") ?(env=Unix.environment()) ~ end; close_out ic; (* read out and err *) - let out = read_all ~size:bufsize oc in + let out = ref "" in + let t_out = + Thread.create + (fun oc -> + out := read_all ~size:bufsize oc) + oc in let err = read_all ~size:bufsize errc in + Thread.join t_out; let status = Unix.close_process_full (oc, ic, errc) in - f (out,err,status) + f (!out,err,status) ) let call_full ?bufsize ?stdin ?env cmd = diff --git a/src/unix/dune b/src/unix/dune index bebb4ead..0aed4277 100644 --- a/src/unix/dune +++ b/src/unix/dune @@ -6,5 +6,4 @@ (optional) (flags :standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string) (ocamlopt_flags :standard (:include ../flambda.flags)) - (libraries unix) - ) + (libraries unix threads))