File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
src/main/java/com/bazel_diff Expand file tree Collapse file tree 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 {
104104 ProcessBuilder pb = new ProcessBuilder (cmd ).directory (workingDirectory .toFile ());
105105 Process process = pb .start ();
106106 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+
107129 while (true ) {
108130 Build .Target target = Build .Target .parseDelimitedFrom (process .getInputStream ());
109131 if (target == null ) break ; // EOF
110132 targets .add (target );
111133 }
134+
135+ tStdError .interrupt ();
112136
113137 Files .delete (tempFile );
114138
You can’t perform that action at this time.
0 commit comments