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:42:06 UTC

[maven-surefire] branch gh-ci updated (b99a35e -> 85eaf43)

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.


 discard b99a35e  investigate
 discard 5d38e7f  java.net.BindException: Cannot assign requested address
     add d5beee5  docs: fix typo
     new 85eaf43  java.net.BindException: Cannot assign requested address

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (b99a35e)
            \
             N -- N -- N   refs/heads/gh-ci (85eaf43)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 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.


Summary of changes:
 .github/workflows/maven.yml                                         | 3 ---
 maven-surefire-plugin/src/site/markdown/multilineexceptions.md      | 2 +-
 .../apache/maven/surefire/api/util/internal/AsyncSocketTest.java    | 6 +++---
 3 files changed, 4 insertions(+), 7 deletions(-)

[maven-surefire] 01/01: 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 85eaf430128bb753256f5764ca029213b30e8f1b
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 ++++++++++++++++++++--
 .../api/util/internal/AsyncSocketTest.java         |  6 ++--
 2 files changed, 35 insertions(+), 6 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
     {
diff --git a/surefire-api/src/test/java/org/apache/maven/surefire/api/util/internal/AsyncSocketTest.java b/surefire-api/src/test/java/org/apache/maven/surefire/api/util/internal/AsyncSocketTest.java
index f4cb773..afadc9f 100644
--- a/surefire-api/src/test/java/org/apache/maven/surefire/api/util/internal/AsyncSocketTest.java
+++ b/surefire-api/src/test/java/org/apache/maven/surefire/api/util/internal/AsyncSocketTest.java
@@ -65,7 +65,7 @@ public class AsyncSocketTest
 
     private volatile InetSocketAddress address;
 
-    @Test
+    @Test( timeout = 10_000L )
     public void test() throws Exception
     {
         int forks = 2;
@@ -80,7 +80,7 @@ public class AsyncSocketTest
         AsynchronousChannelGroup group = AsynchronousChannelGroup.withThreadPool( executorService );
         AsynchronousServerSocketChannel server = AsynchronousServerSocketChannel.open( group );
         setTrueOptions( server, SO_REUSEADDR, TCP_NODELAY, SO_KEEPALIVE );
-        InetAddress ip = InetAddress.getLocalHost();
+        InetAddress ip = InetAddress.getLoopbackAddress();
         server.bind( new InetSocketAddress( ip, 0 ), 1 );
         address = (InetSocketAddress) server.getLocalAddress();
 
@@ -192,7 +192,7 @@ public class AsyncSocketTest
     @SuppressWarnings( "checkstyle:magicnumber" )
     private void client() throws Exception
     {
-        InetSocketAddress hostAddress = new InetSocketAddress( InetAddress.getLocalHost(), address.getPort() );
+        InetSocketAddress hostAddress = new InetSocketAddress( InetAddress.getLoopbackAddress(), address.getPort() );
         AsynchronousSocketChannel clientSocketChannel = AsynchronousSocketChannel.open();
         clientSocketChannel.connect( hostAddress ).get(); // Wait until connection is done.
         InputStream is = new BufferedInputStream( newInputStream( clientSocketChannel ), 64 * 1024 );