sijie closed pull request #1055: [Merge Yahoo repo] YBK-154: Add sleep after
finding free port given OS time to release it
URL: https://github.com/apache/bookkeeper/pull/1055
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/PortManager.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/PortManager.java
index d52e9c7f8..0a4b8ab0e 100644
---
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/PortManager.java
+++
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/PortManager.java
@@ -20,9 +20,7 @@
*/
package org.apache.bookkeeper.test;
-import java.io.IOException;
import java.net.ServerSocket;
-
/**
* Port manager allows a base port to be specified on the commandline.
* Tests will then use ports, counting up from this base port.
@@ -32,19 +30,18 @@
private static int nextPort = getBasePort();
public static synchronized int nextFreePort() {
+ int exceptionCount = 0;
while (true) {
- ServerSocket ss = null;
- try {
- int port = nextPort++;
- ss = new ServerSocket(port);
- ss.setReuseAddress(true);
+ int port = nextPort++;
+ try (ServerSocket ss = new ServerSocket(port)) {
+ ss.close();
+ //Give it some time to truly close the connection
+ Thread.sleep(100);
return port;
- } catch (IOException ioe) {
- } finally {
- if (ss != null) {
- try {
- ss.close();
- } catch (IOException ioe) {}
+ } catch (Exception e) {
+ exceptionCount++;
+ if (exceptionCount > 5) {
+ throw new RuntimeException(e);
}
}
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services