Browse Source

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 years ago
parent
commit
0fc3c7128b
1 changed files with 5 additions and 1 deletions
  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