reduce ephemeral port range to avoid flaky test.
Many Linux kernels use the port range 32768 to 60999 PiperOrigin-RevId: 353901866 Change-Id: I4dfde7189b5cc44b06ed5e807114a87f8a1d3344
This commit is contained in:
parent
2833b3d945
commit
c0948d3b29
@ -28,6 +28,10 @@ limitations under the License.
|
|||||||
#include "tensorflow/core/platform/logging.h"
|
#include "tensorflow/core/platform/logging.h"
|
||||||
#include "tensorflow/core/platform/strcat.h"
|
#include "tensorflow/core/platform/strcat.h"
|
||||||
|
|
||||||
|
// https://en.wikipedia.org/wiki/Ephemeral_port
|
||||||
|
#define MAX_EPHEMERAL_PORT 60999
|
||||||
|
#define MIN_EPHEMERAL_PORT 32768
|
||||||
|
|
||||||
namespace tensorflow {
|
namespace tensorflow {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
@ -41,7 +45,7 @@ bool IsPortAvailable(int* port, bool is_tcp) {
|
|||||||
int actual_port;
|
int actual_port;
|
||||||
|
|
||||||
CHECK_GE(*port, 0);
|
CHECK_GE(*port, 0);
|
||||||
CHECK_LE(*port, 65535);
|
CHECK_LE(*port, MAX_EPHEMERAL_PORT);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
LOG(ERROR) << "socket() failed: " << strerror(errno);
|
LOG(ERROR) << "socket() failed: " << strerror(errno);
|
||||||
return false;
|
return false;
|
||||||
@ -109,9 +113,11 @@ int PickUnusedPortOrDie() {
|
|||||||
CHECK_LE(trial, kMaximumTrials)
|
CHECK_LE(trial, kMaximumTrials)
|
||||||
<< "Failed to pick an unused port for testing.";
|
<< "Failed to pick an unused port for testing.";
|
||||||
if (trial == 1) {
|
if (trial == 1) {
|
||||||
port = getpid() % (65536 - 30000) + 30000;
|
port = getpid() % (MAX_EPHEMERAL_PORT - MIN_EPHEMERAL_PORT) +
|
||||||
|
MIN_EPHEMERAL_PORT;
|
||||||
} else if (trial <= kNumRandomPortsToPick) {
|
} else if (trial <= kNumRandomPortsToPick) {
|
||||||
port = rand() % (65536 - 30000) + 30000;
|
port = rand() % (MAX_EPHEMERAL_PORT - MIN_EPHEMERAL_PORT) +
|
||||||
|
MIN_EPHEMERAL_PORT;
|
||||||
} else {
|
} else {
|
||||||
port = 0;
|
port = 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user