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

sink: fix concurrent map access in sink manager #2249

Merged
merged 7 commits into from
Jul 16, 2021

Conversation

liuzix
Copy link
Contributor

@liuzix liuzix commented Jul 8, 2021

What problem does this PR solve?

  • There is an unsynchronized access to a shared map, which can cause runtime panic.

What is changed and how it works?

  • Lock it.

Check List

Tests

  • Unit test

Related changes

  • Need to cherry-pick to the release branch

Release note

  • Fix minor runtime panic risk

@liuzix liuzix added status/ptal Could you please take a look? type/bugfix This PR fixes a bug. needs-cherry-pick-release-4.0 Should cherry pick this PR to release-4.0 branch. needs-cherry-pick-release-5.0 Should cherry pick this PR to release-5.0 branch. needs-cherry-pick-release-5.1 Should cherry pick this PR to release-5.1 branch. labels Jul 8, 2021
@liuzix liuzix requested a review from zier-one July 8, 2021 07:21
@ti-chi-bot ti-chi-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jul 8, 2021
@liuzix
Copy link
Contributor Author

liuzix commented Jul 8, 2021

/run-leak-tests

@liuzix liuzix changed the title sink: fix concurrency map access in sink manager sink: fix concurrent map access in sink manager Jul 8, 2021
@liuzix
Copy link
Contributor Author

liuzix commented Jul 9, 2021

/run-leak-tests

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Jul 12, 2021
@@ -92,8 +92,14 @@ func (s *managerSuite) TestManagerRandom(c *check.C) {
var wg sync.WaitGroup
tableSinks := make([]Sink, goroutineNum)
for i := 0; i < goroutineNum; i++ {
tableSinks[i] = manager.CreateTableSink(model.TableID(i), 0)
i := i
Copy link
Contributor

Choose a reason for hiding this comment

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

i := i, maybe j :=i

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The variable i is deliberately shadowed to avoid programmer mistakes

Copy link
Contributor

@ben1009 ben1009 Jul 13, 2021

Choose a reason for hiding this comment

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

Because of closure? But with the same name kind of strange, imo

Copy link
Contributor

Choose a reason for hiding this comment

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

It may seem odd to write

req := req

but it's legal and idiomatic in Go to do this. You get a fresh version of the variable with the same name, deliberately shadowing the loop variable locally but unique to each goroutine.

This way is widely used in Go, ref: https://golang.org/doc/effective_go

@ti-chi-bot
Copy link
Member

@ben1009: Thanks for your review. The bot only counts approvals from reviewers and higher roles in list, but you're still welcome to leave your comments.

In response to this:

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • amyangfei
  • overvenus

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jul 14, 2021
@overvenus
Copy link
Member

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: a256f08

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Jul 14, 2021
@amyangfei
Copy link
Contributor

/run-all-tests

@amyangfei
Copy link
Contributor

/run-leak-tests
/run-integration-tests

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created: #2298.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created: #2299.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created: #2300.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-cherry-pick-release-4.0 Should cherry pick this PR to release-4.0 branch. needs-cherry-pick-release-5.0 Should cherry pick this PR to release-5.0 branch. needs-cherry-pick-release-5.1 Should cherry pick this PR to release-5.1 branch. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. status/ptal Could you please take a look? type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants