Skip to content

Commit

Permalink
Fix Port Manager (apache#5024)
Browse files Browse the repository at this point in the history
  • Loading branch information
aahmed-se authored Aug 28, 2019
1 parent c32b402 commit 9ed91eb
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.nio.CharBuffer;
import java.nio.channels.FileChannel;
Expand All @@ -37,7 +39,7 @@ public class PortManager {

private static final String lockFilename = System.getProperty("test.lockFilename",
"/tmp/pulsar-test-port-manager.lock");
private static final int basePort = Integer.valueOf(System.getProperty("test.basePort", "15000"));
private static final int basePort = Integer.parseInt(System.getProperty("test.basePort", "15000"));

private static final int maxPort = 32000;

Expand Down Expand Up @@ -95,7 +97,9 @@ private synchronized static int probeFreePort(int port) {
port = basePort;
}

try (ServerSocket ss = new ServerSocket(port)) {
try (ServerSocket ss = new ServerSocket()) {
ss.setReuseAddress(false);
ss.bind(new InetSocketAddress(InetAddress.getByName("localhost"), port), 1);
ss.close();
// Give it some time to truly close the connection
Thread.sleep(100);
Expand Down

0 comments on commit 9ed91eb

Please sign in to comment.