googleads / googleads-java-lib

Google Ad Manager SOAP API Client Library for Java
Apache License 2.0
226 stars 360 forks source link

javax.net.ssl.SSLHandshakeException when using Google API #170

Closed ghost closed 5 years ago

ghost commented 5 years ago

Hello Team,

I am encountering javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake exception while making a call to Google Ads API. Any feedback on what could cause this issue will be greatly appreciated.

Below is the stack trace:

Caused by: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:994) ~[?:1.8.0_191] at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367) ~[?:1.8.0_191] at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1395) ~[?:1.8.0_191] at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1379) ~[?:1.8.0_191] at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559) ~[?:1.8.0_191] at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185) ~[?:1.8.0_191] at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1334) ~[?:1.8.0_191] at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1309) ~[?:1.8.0_191] at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:259) ~[?:1.8.0_191] at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:77) ~[google-http-client-1.22.0.jar:?] at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:981) ~[google-http-client-1.22.0.jar:?] at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:283) ~[google-oauth-client-1.22.0.jar:?] at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307) ~[google-oauth-client-1.22.0.jar:?] at com.google.api.client.auth.oauth2.Credential.executeRefreshToken(Credential.java:570) ~[google-oauth-client-1.22.0.jar:?] at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:362) ~[google-api-client-1.22.0.jar:?] at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:489) ~[google-oauth-client-1.22.0.jar:?] at com.google.api.ads.common.lib.auth.OAuth2Helper.callRefreshToken(OAuth2Helper.java:69) ~[ads-lib-4.1.0.jar:?] at com.google.api.ads.common.lib.auth.OfflineCredentials.generateCredential(OfflineCredentials.java:234) ~[ads-lib-4.1.0.jar:?] ... 19 more Caused by: java.io.EOFException: SSL peer shut down incorrectly at sun.security.ssl.InputRecord.read(InputRecord.java:505) ~[?:1.8.0_191] at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:975) ~[?:1.8.0_191] at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367) ~[?:1.8.0_191] at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1395) ~[?:1.8.0_191] at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1379) ~[?:1.8.0_191] at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559) ~[?:1.8.0_191] at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185) ~[?:1.8.0_191] at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1334) ~[?:1.8.0_191] at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1309) ~[?:1.8.0_191] at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:259) ~[?:1.8.0_191] at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:77) ~[google-http-client-1.22.0.jar:?] at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:981) ~[google-http-client-1.22.0.jar:?] at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:283) ~[google-oauth-client-1.22.0.jar:?] at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307) ~[google-oauth-client-1.22.0.jar:?] at com.google.api.client.auth.oauth2.Credential.executeRefreshToken(Credential.java:570) ~[google-oauth-client-1.22.0.jar:?] at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:362) ~[google-api-client-1.22.0.jar:?] at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:489) ~[google-oauth-client-1.22.0.jar:?] at com.google.api.ads.common.lib.auth.OAuth2Helper.callRefreshToken(OAuth2Helper.java:69) ~[ads-lib-4.1.0.jar:?] at com.google.api.ads.common.lib.auth.OfflineCredentials.generateCredential(OfflineCredentials.java:234) ~[ads-lib-4.1.0.jar:?]

nwbirnie commented 5 years ago

This has a couple of common causes:

  1. Sending a large volume of traffic to our servers, so requests are being dropped. (Aim to reduce your total traffic throughput significantly).
  2. A problem with the network configuration between your application and Google.

In either case, could you try this with a different internet connection and see if it works?

ghost commented 5 years ago

Thanks for your response!

This seems to only happen sporadically. Unfortunately, verifying with a different internet connection is not an options for us. Since this is not consistent, can we remove the connectivity as the suspect and can there be other reasons of why this occurs intermittently?

nwbirnie commented 5 years ago

It's likely that this is occurring due to a flood of inbound traffic to our backends from a single IP address. Can you check how many requests per second are being sent please? Ideally, you should aim to reduce this to single digit numbers.

ghost commented 5 years ago

Hi, but if the issue is due to the large no. of requests per second, should it not lead to Rate Exceeded Error instead of SSLHandshakeException? For Rate Exceeded errors, we have handled at our end to retry after the specified delay. Can you please suggest?

nwbirnie commented 5 years ago

In cases of very high traffic levels the Rate Exceeded error would not be triggered, instead the connection will simply be dropped, leading to the SSLHandshakeException. The best thing to do is check your total throughput to Google APIs, not just the AdWords API, originating from the same IP address. Feel free to share this if you'd like to check that this is at a reasonable level.