Skip to content

Commit

Permalink
[FLINK-10213] Task managers cache a negative DNS lookup of the blob s…
Browse files Browse the repository at this point in the history
…erver indefinitely

* Added a test case for unresolved InetSocketAddresses that fails before the fix
* Updated BlobClient to create the socket using the hostname and port

Added a check in the BlobClientTest.testUnresolvedInetSocketAddress() that the client is connected.

This closes apache#6862.
  • Loading branch information
joey authored and tillrohrmann committed Jun 20, 2020
1 parent f66556c commit a5527e3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ public BlobClient(InetSocketAddress serverAddress, Configuration clientConfig) t
socket = new Socket();
}

socket.connect(serverAddress, clientConfig.getInteger(BlobServerOptions.CONNECT_TIMEOUT));
// Establish the socket using the hostname and port. This avoids a potential issue where the
// InetSocketAddress can cache a failure in hostname resolution forever.
socket.connect(
new InetSocketAddress(
serverAddress.getHostName(),
serverAddress.getPort()),
clientConfig.getInteger(BlobServerOptions.CONNECT_TIMEOUT));
socket.setSoTimeout(clientConfig.getInteger(BlobServerOptions.SO_TIMEOUT));
}
catch (Exception e) {
Expand Down Expand Up @@ -185,6 +191,10 @@ public boolean isClosed() {
return this.socket.isClosed();
}

public boolean isConnected() {
return socket.isConnected();
}

// --------------------------------------------------------------------------------------------
// GET
// --------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

/**
Expand Down Expand Up @@ -491,7 +492,6 @@ private static void uploadJarFile(
}
}


/**
* Tests the socket operation timeout.
*/
Expand Down Expand Up @@ -519,6 +519,14 @@ public void testSocketTimeout() {
}
}

@Test
public void testUnresolvedInetSocketAddress() throws Exception {
try (BlobClient client = new BlobClient(
InetSocketAddress.createUnresolved("localhost", getBlobServer().getPort()), getBlobClientConfig())) {
assertTrue(client.isConnected());
}
}

static class TestBlobServer extends BlobServer {

private volatile long blockingMillis = 0;
Expand Down

0 comments on commit a5527e3

Please sign in to comment.