diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2017-05-05 08:47:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-05 08:47:03 +0800 |
commit | 0f3923c4d736abb59e5897e79b8010edd69ea814 (patch) | |
tree | 0970d145c8fc46318088ded56d9cf046c10d7d40 | |
parent | b6206e47889c737576c0f77e35eae44602023d2a (diff) | |
download | gitea-0f3923c4d736abb59e5897e79b8010edd69ea814.tar.gz gitea-0f3923c4d736abb59e5897e79b8010edd69ea814.zip |
fix potential lock when sqlite (#1647)
-rw-r--r-- | models/pull.go | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/models/pull.go b/models/pull.go index 07c58446da..aba1046402 100644 --- a/models/pull.go +++ b/models/pull.go @@ -1058,29 +1058,30 @@ func (pr *PullRequest) checkAndUpdateStatus() { // TODO: test more pull requests at same time. func TestPullRequests() { prs := make([]*PullRequest, 0, 10) - x.Iterate(PullRequest{ - Status: PullRequestStatusChecking, - }, - func(idx int, bean interface{}) error { - pr := bean.(*PullRequest) - - if err := pr.GetBaseRepo(); err != nil { - log.Error(3, "GetBaseRepo: %v", err) - return nil - } - if pr.manuallyMerged() { - return nil - } - if err := pr.testPatch(); err != nil { - log.Error(3, "testPatch: %v", err) - return nil - } - prs = append(prs, pr) - return nil - }) + + err := x.Where("status = ?", PullRequestStatusChecking).Find(&prs) + if err != nil { + log.Error(3, "Find Checking PRs", err) + return + } + + var checkedPRs = make(map[int64]struct{}) // Update pull request status. for _, pr := range prs { + checkedPRs[pr.ID] = struct{}{} + if err := pr.GetBaseRepo(); err != nil { + log.Error(3, "GetBaseRepo: %v", err) + continue + } + if pr.manuallyMerged() { + continue + } + if err := pr.testPatch(); err != nil { + log.Error(3, "testPatch: %v", err) + continue + } + pr.checkAndUpdateStatus() } @@ -1089,7 +1090,12 @@ func TestPullRequests() { log.Trace("TestPullRequests[%v]: processing test task", prID) pullRequestQueue.Remove(prID) - pr, err := GetPullRequestByID(com.StrTo(prID).MustInt64()) + id := com.StrTo(prID).MustInt64() + if _, ok := checkedPRs[id]; ok { + continue + } + + pr, err := GetPullRequestByID(id) if err != nil { log.Error(4, "GetPullRequestByID[%s]: %v", prID, err) continue |