google-cloud-java icon indicating copy to clipboard operation
google-cloud-java copied to clipboard

Retry javax.net.ssl.SSLHandshakeException

Open Dima1224 opened this issue 9 years ago • 4 comments

The storage lib doesn't currently consider SSLHandshakeException retryable.

From BaseServiceException:

protected boolean isRetryable(boolean idempotent, IOException exception) {
    boolean exceptionIsRetryable = exception instanceof SocketTimeoutException
        || exception instanceof SocketException
        || "insufficient data written".equals(exception.getMessage());
    return idempotent && exceptionIsRetryable;
  }

But the following type of exception should be retried in the same way a SocketException is retried. Exception in thread "main" com.google.cloud.storage.StorageException: Remote host closed connection during handshake at com.google.cloud.storage.spi.DefaultStorageRpc.translate(DefaultStorageRpc.java:202) at com.google.cloud.storage.spi.DefaultStorageRpc.list(DefaultStorageRpc.java:294) at com.google.cloud.storage.StorageImpl$8.call(StorageImpl.java:297) at com.google.cloud.storage.StorageImpl$8.call(StorageImpl.java:294) at com.google.cloud.RetryHelper.doRetry(RetryHelper.java:179) at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:244) at com.google.cloud.storage.StorageImpl.listBlobs(StorageImpl.java:293) at com.google.cloud.storage.StorageImpl.access$300(StorageImpl.java:74) at com.google.cloud.storage.StorageImpl$BlobPageFetcher.getNextPage(StorageImpl.java:249) at com.google.cloud.PageImpl.getNextPage(PageImpl.java:124) at com.google.cloud.PageImpl$PageIterator.computeNext(PageImpl.java:66) at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:143) at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:138) at LoadSldToSpanner.main(LoadSldToSpanner.java:63) Caused by: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:953) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343) at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185) at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153) at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:93) at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:972) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469) at com.google.cloud.storage.spi.DefaultStorageRpc.list(DefaultStorageRpc.java:286) ... 12 more Caused by: java.io.EOFException: SSL peer shut down incorrectly at sun.security.ssl.InputRecord.read(InputRecord.java:482) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:934) ... 24 more

Dima1224 avatar Mar 16 '17 20:03 Dima1224

@Dima1224 Is this type of error mostly intermittent in your application or not ? I'm curious whether this exception is due to lost connection or underlying SSL-related issues (such as incompatible SSL protocols, client-side cert problems, etc.).

neozwu avatar Apr 19 '17 05:04 neozwu

This particular exception happens rarely. But various seemingly retriable exceptions (network related or service related) not being retried by the new library are a common theme. Maybe I should create a separate ticket for this, but here's the latest example:

Exception in thread "pool-3-thread-136" com.google.cloud.storage.StorageException: 503 Service Unavailable Service Unavailable at com.google.cloud.storage.spi.DefaultStorageRpc.translate(DefaultStorageRpc.java:202) at com.google.cloud.storage.spi.DefaultStorageRpc.delete(DefaultStorageRpc.java:428) at com.google.cloud.storage.StorageImpl$13.call(StorageImpl.java:386) at com.google.cloud.storage.StorageImpl$13.call(StorageImpl.java:383) at com.google.cloud.RetryHelper.doRetry(RetryHelper.java:179) at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:244) at com.google.cloud.storage.StorageImpl.delete(StorageImpl.java:383) at com.google.cloud.storage.StorageImpl.delete(StorageImpl.java:396) at com.spins.google.api.CloudStorage$7.run(CloudStorage.java:647) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)

In this case, a "503 service unavailable" was not retried by RetryHelper.

Dima1224 avatar Apr 19 '17 17:04 Dima1224

@Dima1224 Thanks for the info. "503" definitely should be retried. I believe we implemented it as retriable (https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageException.java#L38). Is it possible it's actually been retried but keeps failing ?

neozwu avatar Apr 19 '17 17:04 neozwu

@neozwu unfortunately, no. I've created a ticket for a similar issue in the past: https://github.com/GoogleCloudPlatform/google-cloud-java/issues/1545. The stack trace seemed the indicate that the exception was recognized as a 503 when in reality it was not due to a bug in the exception conversion logic. I suspect there is a similar problem here, also hidden by the exception's toString logic.

As a side note - it would be helpful if the "NonRetriableException" and "RetriesExhaustedException" wrappers weren't stripped from the exception so we could know for sure if the exception was retried or deemed unretriable.

Dima1224 avatar Apr 19 '17 18:04 Dima1224