Context Canceled when using Go with BigQuery

1.2k views Asked by At

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"
1

There are 1 answers

0
Dominik On

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.