Skip to content

Commit 2729699

Browse files
committed
Do not use future to background the process reading (leaves non-daemon thread)
1 parent 9a0b91c commit 2729699

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Changelog
22
===========
33

4+
* next
5+
* Don't use future to background the process reading (leaves non-daemon thread)
46
* 2.5.186 on Feb 11, 2023
57
* Don't block on big git output
68
* 2.4.181 on Jun 19, 2022

src/main/clojure/clojure/tools/gitlibs/impl.clj

+12-5
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,23 @@
2424
(binding [*out* *err*]
2525
(apply println msgs)))
2626

27-
(defn capture
28-
"Reads from input-stream until EOF and returns a String (or nil if 0 length).
29-
Takes same opts as clojure.java.io/copy - :buffer and :encoding"
27+
(defn- capture
28+
"Reads from input-stream until EOF and returns a String (or nil if 0 length)."
3029
[^InputStream input-stream]
3130
(let [writer (StringWriter.)]
3231
(jio/copy input-stream writer)
3332
(let [s (str/trim (.toString writer))]
3433
(when-not (zero? (.length s))
3534
s))))
3635

36+
(defmacro background
37+
[& body]
38+
`(let [result# (promise)]
39+
(doto (Thread. (fn [] (deliver result# (do ~@body))))
40+
(.setDaemon true)
41+
(.start))
42+
result#))
43+
3744
(defn- run-git
3845
[& args]
3946
(let [{:gitlibs/keys [command debug terminal]} @config/CONFIG
@@ -44,8 +51,8 @@
4451
_ (when debug (.redirectError proc-builder ProcessBuilder$Redirect/INHERIT))
4552
_ (when-not terminal (.put (.environment proc-builder) "GIT_TERMINAL_PROMPT" "0"))
4653
proc (.start proc-builder)
47-
out (future (capture (.getInputStream proc)))
48-
err (future (capture (.getErrorStream proc))) ;; if debug is true, stderr will be redirected instead
54+
out (background (capture (.getInputStream proc)))
55+
err (background (capture (.getErrorStream proc))) ;; if debug is true, stderr will be redirected instead
4956
exit (.waitFor proc)]
5057
{:args command-args, :exit exit, :out @out, :err @err})))
5158

0 commit comments

Comments
 (0)