Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestMemberTestSuite failed because of data race #6668

Closed
TonsnakeLin opened this issue Jun 25, 2023 · 2 comments
Closed

TestMemberTestSuite failed because of data race #6668

TonsnakeLin opened this issue Jun 25, 2023 · 2 comments
Labels

Comments

@TonsnakeLin
Copy link
Contributor

Bug Report

What did you do?

run unit test case TestMemberTestSuite with race.

What did you expect to see?

It runs successfully.

What did you see instead?

img_v2_3e026176-3957-4011-b960-0a47d1fb8c5g
It appears occasionally.

What version of PD are you using (pd-server -V)?

V6.5.3

@TonsnakeLin TonsnakeLin added the type/bug The issue is confirmed as a bug. label Jun 25, 2023
@TonsnakeLin
Copy link
Contributor Author

TonsnakeLin commented Jun 25, 2023

The race generated when initializeing tsoAllocator failed at (3) bellow. At this moment, am.ResetAllocatorGroup at (1) will read the variable Leadership.keepAliveCancelFunc and allocator.KeepAllocatorLeader will write the variable Leadership.keepAliveCancelFunc concurrently, the race is generated.

func (am *AllocatorManager) campaignAllocatorLeader(
	loopCtx context.Context,
	allocator *LocalTSOAllocator,
	dcLocationInfo *pdpb.GetDCLocationInfoResponse,
	isNextLeader bool,
) {
	defer am.ResetAllocatorGroup(allocator.GetDCLocation())         // (1)
	// Maintain the Local TSO Allocator leader
	go allocator.KeepAllocatorLeader(ctx)                                        // (2)

	if err := allocator.Initialize(int(dcLocationInfo.Suffix)); err != nil {  // (3)
            ...
            return
        }
        ...
}

This issue will leads to panic or leak goroutines after starting pd-server.

How to fix? We should initialize the tsoAllocator when KeepAllocatorLeader goroutine has been started.

@lhy1024
Copy link
Contributor

lhy1024 commented Jun 28, 2023

It has been fixed by #6636, I will pick it to oldder version #6701 #6702 #6703 #6704

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants