0

I am getting the below exception when my REST API tries to connect to a Google BigQuery account on UAT environment.

2023-01-30 02:12:59.823 ERROR 8 --- [nio-8080-exec-9] o.a.c.c.C.[.[.[.[dispatcherServlet]      : Servlet.service() for servlet [dispatcherServlet] in context with path [/api/users] threw exception [Request processing failed; nested exception is com.google.cloud.bigquery.BigQueryException: Error getting access token for service account: Connection reset, iss: <somename>.iam.gserviceaccount.com] with root cause

java.net.SocketException: Connection reset
    at java.base/java.net.SocketInputStream.read(Unknown Source) ~[na:na]
    at java.base/java.net.SocketInputStream.read(Unknown Source) ~[na:na]
    at java.base/sun.security.ssl.SSLSocketInputRecord.read(Unknown Source) ~[na:na]
    at java.base/sun.security.ssl.SSLSocketInputRecord.readHeader(Unknown Source) ~[na:na]
    at java.base/sun.security.ssl.SSLSocketInputRecord.decode(Unknown Source) ~[na:na]
    at java.base/sun.security.ssl.SSLTransport.decode(Unknown Source) ~[na:na]
    at java.base/sun.security.ssl.SSLSocketImpl.decode(Unknown Source) ~[na:na]
    at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(Unknown Source) ~[na:na]
    at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) ~[na:na]
    at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) ~[na:na]
    at java.base/sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source) ~[na:na]
    at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source) ~[na:na]
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(Unknown Source) ~[na:na]
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source) ~[na:na]
    at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(Unknown Source) ~[na:na]
    at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:113) ~[google-http-client-1.40.0.jar!/:1.40.0]
    at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:84) ~[google-http-client-1.40.0.jar!/:1.40.0]
    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1012) ~[google-http-client-1.40.0.jar!/:1.40.0]
    at com.google.auth.oauth2.ServiceAccountCredentials.refreshAccessToken(ServiceAccountCredentials.java:602) ~[google-auth-library-oauth2-http-1.1.0.jar!/:na]
    at com.google.auth.oauth2.OAuth2Credentials$1.call(OAuth2Credentials.java:243) ~[google-auth-library-oauth2-http-1.1.0.jar!/:na]
    at com.google.auth.oauth2.OAuth2Credentials$1.call(OAuth2Credentials.java:240) ~[google-auth-library-oauth2-http-1.1.0.jar!/:na]
    at java.base/java.util.concurrent.FutureTask.run(Unknown Source) ~[na:na]
    at com.google.common.util.concurrent.DirectExecutor.execute(DirectExecutor.java:30) ~[guava-30.1.1-jre.jar!/:na]
    at com.google.auth.oauth2.OAuth2Credentials$AsyncRefreshResult.executeIfNew(OAuth2Credentials.java:567) ~[google-auth-library-oauth2-http-1.1.0.jar!/:na]
    at com.google.auth.oauth2.OAuth2Credentials.asyncFetch(OAuth2Credentials.java:206) ~[google-auth-library-oauth2-http-1.1.0.jar!/:na]
    at com.google.auth.oauth2.OAuth2Credentials.getRequestMetadata(OAuth2Credentials.java:156) ~[google-auth-library-oauth2-http-1.1.0.jar!/:na]
    at com.google.auth.oauth2.ServiceAccountCredentials.getRequestMetadata(ServiceAccountCredentials.java:1022) ~[google-auth-library-oauth2-http-1.1.0.jar!/:na]
    at com.google.auth.http.HttpCredentialsAdapter.initialize(HttpCredentialsAdapter.java:96) ~[google-auth-library-oauth2-http-1.1.0.jar!/:na]
    at com.google.cloud.http.HttpTransportOptions$1.initialize(HttpTransportOptions.java:159) ~[google-cloud-core-http-2.1.2.jar!/:2.1.2]
    at com.google.api.client.http.HttpRequestFactory.buildRequest(HttpRequestFactory.java:91) ~[google-http-client-1.40.0.jar!/:1.40.0]
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.buildHttpRequest(AbstractGoogleClientRequest.java:404) ~[google-api-client-1.32.1.jar!/:1.32.1]
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:514) ~[google-api-client-1.32.1.jar!/:1.32.1]
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:455) ~[google-api-client-1.32.1.jar!/:1.32.1]
    at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:565) ~[google-api-client-1.32.1.jar!/:1.32.1]
    at com.google.cloud.bigquery.spi.v2.HttpBigQueryRpc.queryRpc(HttpBigQueryRpc.java:650) ~[google-cloud-bigquery-2.1.6.jar!/:2.1.6]
    at com.google.cloud.bigquery.BigQueryImpl$35.call(BigQueryImpl.java:1284) ~[google-cloud-bigquery-2.1.6.jar!/:2.1.6]
    at com.google.cloud.bigquery.BigQueryImpl$35.call(BigQueryImpl.java:1281) ~[google-cloud-bigquery-2.1.6.jar!/:2.1.6]
    at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:105) ~[gax-2.4.0.jar!/:2.4.0]
    at com.google.cloud.bigquery.BigQueryRetryHelper.run(BigQueryRetryHelper.java:85) ~[google-cloud-bigquery-2.1.6.jar!/:2.1.6]
    at com.google.cloud.bigquery.BigQueryRetryHelper.runWithRetries(BigQueryRetryHelper.java:49) ~[google-cloud-bigquery-2.1.6.jar!/:2.1.6]
    at com.google.cloud.bigquery.BigQueryImpl.queryRpc(BigQueryImpl.java:1280) ~[google-cloud-bigquery-2.1.6.jar!/:2.1.6]
    at com.google.cloud.bigquery.BigQueryImpl.query(BigQueryImpl.java:1268) ~[google-cloud-bigquery-2.1.6.jar!/:2.1.6]

Below is the snippet that executes the query on BigQuery

public TableResult runQuery(String query) throws InterruptedException {
        try {
            bigquery = BigQueryOptions.newBuilder().setProjectId(bigQueryApplicationProperties.getProjectId()).setCredentials(GoogleCredentialsUtility.getCredentials(googleCredentials)).build().getService();
        } catch (IOException ex) {
            throw new BigQuerySearchException("IO Exception thrown - can't find google credentials file", ex);
        }
        QueryJobConfiguration queryConfig = QueryJobConfiguration.newBuilder(query).build();

        
        return bigquery.query(queryConfig);

    }

The same code on my local works fine. Should I move my cacerts file from local to UAT env?

Andulos
  • 433
  • 6
  • 20
  • Hi @Andulos, this exception is caused due to error in the underlying protocol such as TCP error. I would suggest you to check the logs and find out whether the client has closed the TCP connection due to timeout or Runtime Exception at the client end. Let me know if that helps. – Shipra Sarkar Feb 01 '23 at 07:31

0 Answers0