Closed
Description
Description
While testing a new linting rule for revive
I've found a datarace in the function CreateReviews
of gitea/services/migrations/gitea_uploader.go
// CreateReviews create pull request reviews of currently migrated issues
func (g *GiteaLocalUploader) CreateReviews(reviews ...*base.Review) error {
// ...
for _, comment := range review.Comments {
// ...
go func() {
if err := git.GetRepoRawDiffForFile(g.gitRepo, pr.MergeBase, headCommitID, git.RawDiffNormal, comment.TreePath, writer); err != nil {
// We should ignore the error since the commit maybe removed when force push to the pull request
log.Warn("GetRepoRawDiffForFile failed when migrating [%s, %s, %s, %s]: %v", g.gitRepo.Path, pr.MergeBase, headCommitID, comment.TreePath, err)
}
_ = writer.Close()
}()
// ...
The range value comment
is captured (by-reference) in the go-routine. Thus at each iteration the value of comment
will change and it will (potentially) affect all previously triggered go-routines (as modeled here)
Gitea Version
Can you reproduce the bug on the Gitea demo site?
No
Log Gist
No response
Screenshots
No response
Git Version
No response
Operating System
No response
How are you running Gitea?
I do not run Gitea. I use its code base as sandbox for testing new linting rules
Database
No response