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

Fix data race on migrate repository #5224

Merged
merged 3 commits into from
Oct 30, 2018

Conversation

lunny
Copy link
Member

@lunny lunny commented Oct 30, 2018

The data race occupied when both two go routines run repo.getOwner and it will set repo.Owner. Since UpdateRepoIndexer(repo) will send the repo pointer to another goroutine, this PR lets it runs after all other operations finished to resolve the data race. A complete solution to resolve this like problem is to change UpdateRepoIndexer(neededRepoInfo) to only copy needed information from repo.

@lunny
Copy link
Member Author

lunny commented Oct 30, 2018

partially fix #5189

@bkcsoft bkcsoft added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Oct 30, 2018
@codecov-io
Copy link

codecov-io commented Oct 30, 2018

Codecov Report

Merging #5224 into master will decrease coverage by 0.07%.
The diff coverage is 57.14%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5224      +/-   ##
==========================================
- Coverage   37.54%   37.47%   -0.08%     
==========================================
  Files         310      310              
  Lines       45929    45934       +5     
==========================================
- Hits        17245    17213      -32     
- Misses      26214    26244      +30     
- Partials     2470     2477       +7
Impacted Files Coverage Δ
models/repo.go 43.55% <57.14%> (-0.02%) ⬇️
models/repo_indexer.go 44.49% <0%> (-10.6%) ⬇️
modules/indexer/repo.go 64.28% <0%> (-5.56%) ⬇️
models/repo_list.go 62.2% <0%> (-1.17%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0ba5794...5c3dfa8. Read the comment docs.

@typeless
Copy link
Contributor

@lunny LGTM.

To prevent such bugs in the future, are the following rules correct (required)?

  1. the values of Repository should not be copied.
  2. the pointers of Repository should not be passed across the boundary of gourintes.

@lunny
Copy link
Member Author

lunny commented Oct 30, 2018

@typeless I agree with 2, but don't know why we need 1. Copy always cannot result in data race.

@typeless
Copy link
Contributor

@lunny regarding data race, 1. is not required. I made that assumption to be easier to reason about it. I thought the Repository is supposed to be immutable after loaded, but it's not. If I understand correctly, the code updates the Repository objects, and all changes of the objects would be synced back to the database.

If we have two copies of Repository objects for the same git repo and one of them is updated, then the two copies of Repository objects would be inconsistent, which I think would be a problem.

@bkcsoft bkcsoft added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Oct 30, 2018
@bkcsoft bkcsoft added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Oct 30, 2018
@techknowlogick techknowlogick merged commit e61c6cd into go-gitea:master Oct 30, 2018
@lunny lunny deleted the lunny/fix_migrate_data_race branch October 31, 2018 01:44
lunny added a commit to lunny/gitea that referenced this pull request Oct 31, 2018
@lafriks lafriks added the backport/done All backports for this PR have been created label Nov 8, 2018
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/done All backports for this PR have been created lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants