tiflow icon indicating copy to clipboard operation
tiflow copied to clipboard

Data race in `cdc/redo` tests due to concurrent modification of global variable `redo.DefaultGCIntervalInMs`

Open wlwilliamx opened this issue 2 months ago • 0 comments

https://do.pingcap.net/jenkins/blue/organizations/jenkins/pingcap%2Ftiflow%2Frelease-6.5%2Fghpr_verify/detail/ghpr_verify/640/pipeline/186/

A data race is occurring in the cdc/redo test suite, detectable when running tests with the -race flag.

The test TestGCAndCleanup in cdc/redo/meta_manager_test.go is marked to run in parallel using t.Parallel(). However, this test function modifies the global variable redo.DefaultGCIntervalInMs.

When multiple tests run in parallel, this causes a concurrent write (a data race) on this global variable, leading to flaky and unreliable test results.

It should be placed in the package-level setup function TestMain (in cdc/redo/main_test.go). This function runs once, before any tests in the package are executed. This sets the variable for all tests in the package without causing a concurrent write conflict. A defer statement in TestMain will ensure the original value is restored after all tests complete.

wlwilliamx avatar Oct 20 '25 04:10 wlwilliamx