File tree 1 file changed +24
-0
lines changed
src/main/java/com/bazel_diff
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -104,11 +104,35 @@ private List<Build.Target> performBazelQuery(String query) throws IOException {
104
104
ProcessBuilder pb = new ProcessBuilder (cmd ).directory (workingDirectory .toFile ());
105
105
Process process = pb .start ();
106
106
ArrayList <Build .Target > targets = new ArrayList <>();
107
+
108
+ // Prevent process hang in the case where bazel writes to stderr.
109
+ // See https://stackoverflow.com/questions/3285408/java-processbuilder-resultant-process-hangs
110
+ BufferedReader stdError = new BufferedReader (new InputStreamReader (process .getErrorStream ()));
111
+ Thread tStdError = new Thread (new Runnable () {
112
+ String line = null ;
113
+ public void run () {
114
+ try {
115
+ while ((line = stdError .readLine ()) != null ) {
116
+ if (verbose ) {
117
+ System .out .println (line );
118
+ }
119
+
120
+ if (Thread .currentThread ().isInterrupted ()) {
121
+ return ;
122
+ }
123
+ }
124
+ } catch (IOException e ) {}
125
+ }
126
+ });
127
+ tStdError .start ();
128
+
107
129
while (true ) {
108
130
Build .Target target = Build .Target .parseDelimitedFrom (process .getInputStream ());
109
131
if (target == null ) break ; // EOF
110
132
targets .add (target );
111
133
}
134
+
135
+ tStdError .interrupt ();
112
136
113
137
Files .delete (tempFile );
114
138
You can’t perform that action at this time.
0 commit comments