Skip to content

Commit

Permalink
Using localhost (not local loopback) in SurefireForkChannel.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Tibor17 committed Jun 6, 2020
1 parent eb48f1b commit 5f492fa
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ final class SurefireForkChannel extends ForkChannel
super( arguments );
server = open( withThreadPool( THREAD_POOL ) );
setTrueOptions( SO_REUSEADDR, TCP_NODELAY, SO_KEEPALIVE );
InetAddress ip = Inet4Address.getLoopbackAddress();
InetAddress ip = Inet4Address.getLocalHost();
server.bind( new InetSocketAddress( ip, 0 ), 1 );
InetSocketAddress localAddress = (InetSocketAddress) server.getLocalAddress();
localHost = localAddress.getHostString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.URI;
import java.nio.ByteBuffer;
Expand Down Expand Up @@ -98,9 +99,10 @@ public ConsoleLogger getConsoleLogger()
assertThat( channel.getCountdownCloseablePermits() )
.isEqualTo( 3 );

String localHost = InetAddress.getLocalHost().getHostAddress();
assertThat( channel.getForkNodeConnectionString() )
.startsWith( "tcp://127.0.0.1:" )
.isNotEqualTo( "tcp://127.0.0.1:" );
.startsWith( "tcp://" + localHost + ":" )
.isNotEqualTo( "tcp://" + localHost + ":" );

URI uri = new URI( channel.getForkNodeConnectionString() );

Expand Down Expand Up @@ -171,7 +173,7 @@ private Client( int port )
@Override
public void run()
{
try ( Socket socket = new Socket( "127.0.0.1", port ) )
try ( Socket socket = new Socket( InetAddress.getLocalHost().getHostAddress(), port ) )
{
byte[] data = new byte[128];
int readLength = socket.getInputStream().read( data );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void run()
@SuppressWarnings( "checkstyle:magicnumber" )
private void client() throws Exception
{
InetSocketAddress hostAddress = new InetSocketAddress( InetAddress.getLoopbackAddress(), address.getPort() );
InetSocketAddress hostAddress = new InetSocketAddress( InetAddress.getLocalHost(), address.getPort() );
AsynchronousSocketChannel clientSocketChannel = AsynchronousSocketChannel.open();
clientSocketChannel.connect( hostAddress ).get(); // Wait until connection is done.
InputStream is = new BufferedInputStream( newInputStream( clientSocketChannel ), 64 * 1024 );
Expand Down

0 comments on commit 5f492fa

Please sign in to comment.