You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2021/04/15 20:12:51 UTC

[maven-surefire] branch gh-ci created (now b99a35e)

This is an automated email from the ASF dual-hosted git repository.

tibordigana pushed a change to branch gh-ci
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git.


      at b99a35e  investigate

This branch includes the following new commits:

     new 5d38e7f  java.net.BindException: Cannot assign requested address
     new b99a35e  investigate

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[maven-surefire] 02/02: investigate

Posted by ti...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tibordigana pushed a commit to branch gh-ci
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git

commit b99a35ef9dd83be1b00cdb4ed79f5202f0688d56
Author: tibordigana <ti...@gmail.com>
AuthorDate: Thu Apr 15 22:12:44 2021 +0200

    investigate
---
 .github/workflows/maven.yml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
index cc38513..724f51b 100644
--- a/.github/workflows/maven.yml
+++ b/.github/workflows/maven.yml
@@ -46,6 +46,9 @@ jobs:
         with:
           java-version: ${{ matrix.java }}
 
+      - name: print hosts
+        run: cat /etc/hosts
+
       - name: Build with Maven
         run: mvn clean install -e -B -V -nsu --no-transfer-progress -P run-its -Dfailsafe-integration-test-port=8083
 

[maven-surefire] 01/02: java.net.BindException: Cannot assign requested address

Posted by ti...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tibordigana pushed a commit to branch gh-ci
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git

commit 5d38e7f9c564b2d7cbadf827f65ebc438af81728
Author: tibordigana <ti...@gmail.com>
AuthorDate: Thu Apr 15 22:11:50 2021 +0200

    java.net.BindException: Cannot assign requested address
---
 .../surefire/extensions/SurefireForkChannel.java   | 35 ++++++++++++++++++++--
 1 file changed, 32 insertions(+), 3 deletions(-)

diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireForkChannel.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireForkChannel.java
index 640d562..45f262c 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireForkChannel.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireForkChannel.java
@@ -32,14 +32,17 @@ import org.apache.maven.surefire.extensions.util.LineConsumerThread;
 import javax.annotation.Nonnull;
 import java.io.Closeable;
 import java.io.IOException;
+import java.net.BindException;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.SocketOption;
 import java.nio.Buffer;
 import java.nio.ByteBuffer;
+import java.nio.channels.AlreadyBoundException;
 import java.nio.channels.AsynchronousServerSocketChannel;
 import java.nio.channels.AsynchronousSocketChannel;
 import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.UnsupportedAddressTypeException;
 import java.nio.channels.WritableByteChannel;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
@@ -87,14 +90,40 @@ final class SurefireForkChannel extends ForkChannel
         super( arguments );
         server = open( withThreadPool( THREAD_POOL ) );
         setTrueOptions( SO_REUSEADDR, TCP_NODELAY, SO_KEEPALIVE );
-        InetAddress ip = InetAddress.getLoopbackAddress();
-        server.bind( new InetSocketAddress( ip, 0 ), 1 );
-        InetSocketAddress localAddress = (InetSocketAddress) server.getLocalAddress();
+        InetSocketAddress localAddress = bindSocketAddress();
         localHost = localAddress.getHostString();
         localPort = localAddress.getPort();
         sessionId = arguments.getSessionId();
     }
 
+    private InetSocketAddress bindSocketAddress() throws IOException
+    {
+        InetSocketAddress localLoopback = findLocalAddress(InetAddress.getLoopbackAddress()  );
+        if ( localLoopback != null )
+        {
+            return localLoopback;
+        }
+        InetSocketAddress localhost = findLocalAddress( InetAddress.getLocalHost() );
+        if ( localhost != null )
+        {
+            return localhost;
+        }
+        throw new IOException( "Could not find local IP address." );
+    }
+
+    private InetSocketAddress findLocalAddress( InetAddress ip ) throws IOException
+    {
+        try
+        {
+            server.bind( new InetSocketAddress( ip, 0 ), 1 );
+            return (InetSocketAddress) server.getLocalAddress();
+        }
+        catch ( BindException | AlreadyBoundException | UnsupportedAddressTypeException e )
+        {
+            return null;
+        }
+    }
+
     @Override
     public void connectToClient() throws IOException
     {