Marcin_S
Marcin_S

Reputation: 539

Bigquery Client Timeout is Happening

I have the following code :

  private BigQuery bigQuery() throws IOException
        {
            File credentialsPath = new File(path);
            GoogleCredentials credentials;
            try (FileInputStream serviceAccountStream = new FileInputStream(credentialsPath)) {
                credentials = ServiceAccountCredentials.fromStream(serviceAccountStream);
            }

            // Instantiate a client.
            BigQuery bigquery =
                    BigQueryOptions.newBuilder()
                            .setCredentials(credentials)
                            .setProjectId(gcpProject)
                            .build()
                            .getService();

            return bigquery;
        }

And now i calling bigquery API's

            BigQuery bigquery = bigQuery();
            TableId destinationTable = TableId.of(datasetName, TableName);
            QueryJobConfiguration queryConfig = QueryJobConfiguration.newBuilder(getQuery()).build();
            TableResult results = bigquery.query(queryConfig);

I am getting the following error :

com.google.cloud.bigquery.BigQueryException: Read timed out
    at com.google.cloud.bigquery.spi.v2.HttpBigQueryRpc.translate(HttpBigQueryRpc.java:115)
    at com.google.cloud.bigquery.spi.v2.HttpBigQueryRpc.listTableData(HttpBigQueryRpc.java:514)
    at com.google.cloud.bigquery.BigQueryImpl$29.call(BigQueryImpl.java:1129)
    at com.google.cloud.bigquery.BigQueryImpl$29.call(BigQueryImpl.java:1124)
    at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:103)
    at com.google.cloud.RetryHelper.run(RetryHelper.java:76)
    at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:50)
    at com.google.cloud.bigquery.BigQueryImpl.listTableData(BigQueryImpl.java:1123)
    at com.google.cloud.bigquery.BigQueryImpl.listTableData(BigQueryImpl.java:1107)
    at com.google.cloud.bigquery.Job.getQueryResults(Job.java:321)
    at com.google.cloud.bigquery.BigQueryImpl.query(BigQueryImpl.java:1286)
    at com.walmart.uss.trigger.queryEngine.BQQueryEngine.scheduleQuery(BQQueryEngine.java:94)
    at com.walmart.uss.trigger.service.QuerySchedulerService.runQuery(QuerySchedulerService.java:115)
    at com.walmart.uss.trigger.service.QuerySchedulerService$$FastClassBySpringCGLIB$$17f0e797.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:779)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)
    at org.springframework.aop.interceptor.AsyncExecutionInterceptor.lambda$invoke$0(AsyncExecutionInterceptor.java:115)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:750)
Caused by: java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
    at java.net.SocketInputStream.read(SocketInputStream.java:171)
    at java.net.SocketInputStream.read(SocketInputStream.java:141)
    at sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:476)
    at sun.security.ssl.SSLSocketInputRecord.readHeader(SSLSocketInputRecord.java:470)
    at sun.security.ssl.SSLSocketInputRecord.bytesInCompletePacket(SSLSocketInputRecord.java:70)
    at sun.security.ssl.SSLSocketImpl.readApplicationRecord(SSLSocketImpl.java:1364)
    at sun.security.ssl.SSLSocketImpl.access$300(SSLSocketImpl.java:73)
    at sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:973)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:743)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:678)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1600)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1505)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:352)
    at com.google.api.client.http.javanet.NetHttpResponse.<init>(NetHttpResponse.java:36)
    at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:152)
    at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:84)
    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1012)

The error is not happening everytime, it happening ad-hoc basics, if i call my API 10 times then it's failing 7 times and getting result for the rest. Any help what's causing this bigquery time out

Upvotes: 0

Views: 1255

Answers (1)

amarnath harish
amarnath harish

Reputation: 971

try adding retry and http transport settings..

GoogleCredentials credentials = GoogleCredentials.fromStream(new FileInputStream(config.getJson_path()));
        BigQueryOptions.Builder bigQueryOptions = BigQueryOptions.newBuilder()
                .setProjectId(config.getGcp_projectID())
                .setCredentials(credentials)
                .setRetrySettings(RetrySettings.newBuilder()
                        .setMaxAttempts(10)
                        .setRetryDelayMultiplier(1.5)
                        .setTotalTimeout(Duration.ofMinutes(5))
                        .build())
                .setTransportOptions(HttpTransportOptions.newBuilder()
                        .setConnectTimeout(300000)//5 minutes
                        .setReadTimeout(25000)
                        .build());

        bigQuery = bigQueryOptions.build().getService();

Upvotes: 1

Related Questions