简体   繁体   中英

Context Canceled when using Go with BigQuery

I am trying to insert a record to biqquery & here the code which does the insert.

func (s *Storage) Insert(w *warehouse.WarehouseRecord) error {
   event, err := w.Marshal()
   if err != nil {
      return err
   }
   logger.Info("inserting record to big query")
   ins := s.client.Dataset(s.dataSet).Table(event.GetTableName()).Inserter()
   ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
   defer cancel()
   if err := ins.Put(ctx, event); err != nil {
      return err
   }
   return nil
}

When i run my application, the insert fails with error. The error says context canceled , but I am not canceling the context from parent, I suspect its happening inside the client package. Have any one of you come across this error?

Post "https://bigquery.googleapis.com/bigquery/v2/projects/dinesh-dev/datasets/analytics_test/tables/agent/insertAll?alt=json&prettyPrint=false": context canceled{"error":"Post \"https://bigquery.googleapis.com/bigquery/v2/projects/dinesh-dev/datasets/analytics_test/tables/agent/insertAll?alt=json\u0026prettyPrint=false\": context canceled"

Perhaps the context you've given on initialisation of foo.NewClient(ctx, ...) is canceled. This context should not be canceled, see doc :

// Do not cancel the context passed to NewClient: dialing happens asynchronously and the context is used to refresh credentials in the background.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM