pingcap / pingcap/tidb

Concurrent usage of Backoffer which seems not designed to be thread-safe

Open
#55,393 0 comments 0 reactions 0 assignees View on GitHub
affects-5.4 affects-6.1 affects-6.5 affects-7.1 affects-7.5 affects-8.1 severity/moderate sig/transaction type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

The [`Backoffer`](https://github.com/tikv/client-go/blob/4c6b2171b262807c9197bdb58a82d4626fb0495f/config/retry/backoff.go#L59) didn't use mutexes or atomic operations in it to protect its state. Neither is the `Backoff` method read only. This means the `Backoffer` is not designed to be used in concurrent way. However, it looks like it's already concurrently used everywhere. This is possible to lead to unexpected behavior due to data race. Besides, even if it is thread-safe, it's still questionable whether we should reuse the same backoffer when sending concurrent requests.

A list of concurrent usages of `Backoffer` I've found (maybe incomplete for now):

* When coprocessor tasks processed concurrently and meet errors
* client-go transaction layer processing multiple prewirte/commit/pessimistic_lock batches concurrently

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.