SiyaoIsHiding commented on code in PR #1902: URL: https://github.com/apache/cassandra-java-driver/pull/1902#discussion_r1433158316
########## core/src/main/java/com/datastax/oss/driver/internal/core/config/cloud/CloudConfigFactory.java: ########## @@ -225,22 +228,40 @@ protected TrustManagerFactory createTrustManagerFactory( @NonNull protected BufferedReader fetchProxyMetadata( @NonNull URL metadataServiceUrl, @NonNull SSLContext sslContext) throws IOException { - try { - HttpsURLConnection connection = (HttpsURLConnection) metadataServiceUrl.openConnection(); - connection.setSSLSocketFactory(sslContext.getSocketFactory()); - connection.setRequestMethod("GET"); - connection.setRequestProperty("host", "localhost"); - return new BufferedReader( - new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8)); - } catch (ConnectException e) { - throw new IllegalStateException( - "Unable to connect to cloud metadata service. Please make sure your cluster is not parked or terminated", - e); - } catch (UnknownHostException e) { - throw new IllegalStateException( - "Unable to resolve host for cloud metadata service. Please make sure your cluster is not terminated", - e); + HttpsURLConnection connection = null; + int attempt = 0; + while(attempt < METADATA_RETRY_MAX_ATTEMPTS){ + try { + connection = (HttpsURLConnection) metadataServiceUrl.openConnection(); + connection.setSSLSocketFactory(sslContext.getSocketFactory()); + connection.setRequestMethod("GET"); + connection.setRequestProperty("host", "localhost"); + attempt++; + // if this is the last attempt, throw + // else if the response code is not 200, retry + // else, throw + if (attempt != METADATA_RETRY_MAX_ATTEMPTS && connection.getResponseCode() != 200) { Review Comment: I want it to throw the error at the last attempt. Otherwise, a `FileNotFoundException` will become a `DriverTimeoutException` (the dead code at the end). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org