dongtao5055 2017-04-11 07:17
浏览 86
已采纳

转到Bigquery上的DEADLINE_EXCEEDED

Our application sometimes see DEADLINE_EXCEEDED when accessing to Big Query.

import (
    "cloud.google.com/go/bigquery"
    "golang.org/x/net/context"
    "google.golang.org/api/option"
)

func MyFunc(ctx context.Context) {
            :
    client, err := bigquery.NewClient(ctx, PROJECT_ID, option.WithServiceAccountFile(SERVICE_ACCOUNT_JSON_FILE_PATH))
    query := client.Query("SELECT * FROM ....")
    it, err := query.Read(ctx)
    var list []MyStruct
    for {
        var m MyStruct
        err := it.Next(&m)
        if err == iterator.Done {
            break
        }
        if err != nil {
           <Error Handling>
        }
        list = append(list, m)
    }
            :
}

Sometimes we see this error.

Get https://www.googleapis.com/bigquery/v2/projects/myproject/queries/job_zandIeLwH0s8f3FAQ_ORC0zau14?alt=json\u0026startIndex=0\u0026timeoutMs=60000: API error 5 (urlfetch: DEADLINE_EXCEEDED): ('The read operation timed out',)"

It looks timeout is 5 second, but I can' find how can I change timeout seconds.

I read this post, and I modified my source code as below.

ctx_with_deadline, _ := context.WithTimeout(ctx, 1*time.Minute)
httpClient := &http.Client{
    Transport: &oauth2.Transport{
        Base: &urlfetch.Transport{Context: ctx_with_deadline},
    },
}

client, err := bigquery.NewClient(ctx, PROJECT_ID, option.WithServiceAccountFile(SERVICE_ACCOUNT_JSON_FILE_PATH), option.WithHTTPClient(httpClient))

Then I met this error.

Post https://www.googleapis.com/bigquery/v2/projects/myproject/jobs?alt=json: oauth2: Transport's Source is nil

How can I change timeout in Go Bigquery?

  • 写回答

1条回答 默认 最新

  • dpdhf02040 2017-04-11 13:20
    关注

    Use ctx_with_deadline also when creating a new instance of the bigquery client:

    client, err := bigquery.NewClient(ctx_with_deadline, PROJECT_ID, option.WithServiceAccountFile(SERVICE_ACCOUNT_JSON_FILE_PATH‌​), option.WithHTTPClient(httpClient))
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog