-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 problems in git module (quick patch) #19934
Conversation
By using a sync.Once we're limited to configuring this function once and once only per run (which is fine for Gitea as we are currently) but this also applies to the tests too. Any attempt to call this function to reconfigure will fail but that means it could be possible that a different order of calling Tests could cause a different configuration to be set. So ... the first function calling this Init should probably be being called from within the TestMain(s) to ensure that there is a consistent configuration. |
Yes, but the same problem to git.CheckLFSVersion ...... Without a big refactoring, the problem can not be resolved clearly. |
Why I think this PR is enough: Before refactoring:
After the refactoring and this PR:
Indeed, the situation of refactoring the git module is more complex than I thought. IMO at the moment it's impossible to achieve the ideal status with a few PRs, especially there is a blocker in And I am open to learn ideas about how to make the git module better. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we're somewhat forced to do the syncOnce here.
Codecov Report
@@ Coverage Diff @@
## main #19934 +/- ##
==========================================
- Coverage 47.32% 47.30% -0.03%
==========================================
Files 959 965 +6
Lines 133652 134013 +361
==========================================
+ Hits 63252 63389 +137
- Misses 62699 62904 +205
- Partials 7701 7720 +19
Continue to review full report at Codecov.
|
* giteaoffical/main: Fix data-race problems in git module (quick patch) (go-gitea#19934) [skip ci] Updated translations via Crowdin Fix copy/paste of empty lines (go-gitea#19798) Normalize line endings in fomantic build files (go-gitea#19932) Make user profile image show full image on mobile (go-gitea#19840) Custom regexp external issues (go-gitea#17624) Use Golang 1.18 for Gitea 1.17 release (go-gitea#19918) Refactor git module, make Gitea use internal git config (go-gitea#19732) [skip ci] Updated translations via Crowdin
* Fix data-race problems in git module * use HomeDir instead of setting.RepoRootPath Co-authored-by: Lunny Xiao <[email protected]>
This patch is somewhat hacky, it might be the most simple one to resolve the data-race problem in
git.Init
.Details:
Before git refactoring:
git.Init
was only called once inGlobalInitInstalled
, which is incomplete, because the tests also need to init the git module.With the last git refactoring #19732:
git.Init
was called inGlobalInitInstalled
and manyprepareTestEnv
functions, butgit.Init
changes many global variables, then it leads to data-race problem.This PR: introduce
git.InitOnceWithSync
which only changes the global variables once, just like what git.CheckLFSVersion does.Although this PR is not ideal and hacky, (hopefully) it should work and be enough for 1.17 release. In the future, the setting related code should be refactored (eg: by using
atomic.Value
), including thegit.CheckLFSVersion
.