Skip to content

Commit 5e5f4dc

Browse files
craig[bot]kev-cao
andcommitted
Merge #159011
159011: sql: fix nil panic when KV external send request fails r=yuzefovich,michae2 a=kev-cao This fixes a critical bug where a KV external send request will encounter a nil pointer exception if the transaction fails. Fixes: #158782 Release note: None Co-authored-by: Kevin Cao <[email protected]>
2 parents 0dfe683 + c518e97 commit 5e5f4dc

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

pkg/sql/row/kv_batch_fetcher.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,15 +338,18 @@ func makeExternalSpanSendFunc(
338338
}
339339
return nil
340340
})
341-
342-
if res.CPUTime > 0 {
343-
atomic.AddInt64(kvCPUTime, res.CPUTime)
344-
}
345341
// Note that in some code paths there is no concurrency when using the
346342
// sendFunc, but we choose to unconditionally use atomics here since its
347343
// overhead should be negligible in the grand scheme of things anyway.
348344
atomic.AddInt64(batchRequestsIssued, 1)
349-
return res, err
345+
if err != nil {
346+
return nil, err
347+
}
348+
349+
if res.CPUTime > 0 {
350+
atomic.AddInt64(kvCPUTime, res.CPUTime)
351+
}
352+
return res, nil
350353
}
351354
}
352355

0 commit comments

Comments
 (0)