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

pd-client: fix a data race in pd client #660

Merged
merged 3 commits into from
Jun 10, 2017
Merged

Conversation

tiancaiamao
Copy link
Contributor

In the defer statement, req.start is visted after the req object put back to pool.
This may cause data race when another goroutine get the req from pool and reset its req.start.

count := 10
wg.Add(count)
for i := 0; i < count; i++ {
go func(begin chan struct{}, wg *sync.WaitGroup) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why pass begin and wg as parameters? go func() {} won't work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No difference. go func() {} is closure, closure is slightly poor in performance.
I'll update it here, for readability.

@disksing
Copy link
Contributor

LGTM

Copy link
Contributor

@nolouch nolouch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tiancaiamao tiancaiamao merged commit ce8db87 into master Jun 10, 2017
@tiancaiamao tiancaiamao deleted the tiancaiamao/fix-race branch June 10, 2017 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants