Преглед на файлове

session: NewBatch needs a valid speculation execution policy

The old gocql.NewBatch function creates a bad Batch object
that can fail with a nil pointer dereference when executing
an empty batch.

Because the batch is empty, IsIdempotent returns true and then
queryExecutor.executeQuery fails when calling sp.Delay() because
no spec has been set on the Batch by NewBatch.
Vincent Rischmann преди 7 години
родител
ревизия
0fc3c7128b
променени са 1 файла, в които са добавени 5 реда и са изтрити 1 реда
  1. 5 1
      session.go

+ 5 - 1
session.go

@@ -1487,7 +1487,11 @@ type Batch struct {
 //
 // Deprecated: use session.NewBatch instead
 func NewBatch(typ BatchType) *Batch {
-	return &Batch{Type: typ, metrics: &queryMetrics{m: make(map[string]*hostMetrics)}}
+	return &Batch{
+		Type:    typ,
+		metrics: &queryMetrics{m: make(map[string]*hostMetrics)},
+		spec:    &NonSpeculativeExecution{},
+	}
 }
 
 // NewBatch creates a new batch operation using defaults defined in the cluster