olamy commented on code in PR #3650:
URL: https://github.com/apache/maven-surefire/pull/3650#discussion_r4737773659


##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireForkChannel.java:
##########
@@ -271,11 +285,25 @@ protected void job() throws IOException, 
InterruptedException {
     }
 
     private AsynchronousSocketChannel getChannel() throws 
InterruptedException, IOException {
-        try {
-            return session == null ? null : session.get();
-        } catch (ExecutionException e) {
-            Throwable cause = e.getCause();
-            throw cause instanceof IOException ? (IOException) cause : new 
IOException(cause);
+        if (session == null) {
+            return null;
+        }
+        while (true) {
+            // Ask the process, not stdout: a fork may close its stdout and 
still connect later.
+            // Checked before waiting, so the fork still gets a second to 
connect.
+            // Only an error counts: a jvm wrapper script can start java in 
the background and exit 0.
+            boolean forkFailed = process != null && !process.isAlive() && 
process.exitValue() != 0;

Review Comment:
   Good catch, fixed in c7ed59354. An exit 0 now gets 60 seconds to connect, so 
a wrapper script that starts java in the background still works. After that the 
build fails with "The forked VM exited with code 0 before connecting to Maven." 
A non-zero exit still fails after about a second. The new test 
`shouldFailWhenTheForkExits0AndNothingConnects` covers it. It runs with a 2 
second window and hung before the fix.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to