Skip to content

Commit 2904d8d

Browse files
zeripathtechknowlogick
authored andcommitted
Fix sqlite deadlock when assigning to a PR (#5640) (#5642)
* Fix sqlite deadlock when assigning to a PR Fix 5639 Signed-off-by: Andrew Thornton <[email protected]> * More possible deadlocks found and fixed Signed-off-by: Andrew Thornton <[email protected]>
1 parent 109fc79 commit 2904d8d

File tree

6 files changed

+17
-9
lines changed

6 files changed

+17
-9
lines changed

models/issue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,7 @@ func UpdateIssueMentions(e Engine, issueID int64, mentions []string) error {
14021402
}
14031403

14041404
memberIDs := make([]int64, 0, user.NumMembers)
1405-
orgUsers, err := GetOrgUsersByOrgID(user.ID)
1405+
orgUsers, err := getOrgUsersByOrgID(e, user.ID)
14061406
if err != nil {
14071407
return fmt.Errorf("GetOrgUsersByOrgID [%d]: %v", user.ID, err)
14081408
}

models/issue_assignees.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ func (issue *Issue) loadAssignees(e Engine) (err error) {
4444

4545
// GetAssigneesByIssue returns everyone assigned to that issue
4646
func GetAssigneesByIssue(issue *Issue) (assignees []*User, err error) {
47-
err = issue.loadAssignees(x)
47+
return getAssigneesByIssue(x, issue)
48+
}
49+
50+
func getAssigneesByIssue(e Engine, issue *Issue) (assignees []*User, err error) {
51+
err = issue.loadAssignees(e)
4852
if err != nil {
4953
return assignees, err
5054
}
@@ -173,7 +177,7 @@ func (issue *Issue) changeAssignee(sess *xorm.Session, doer *User, assigneeID in
173177
issue.PullRequest.Issue = issue
174178
apiPullRequest := &api.PullRequestPayload{
175179
Index: issue.Index,
176-
PullRequest: issue.PullRequest.APIFormat(),
180+
PullRequest: issue.PullRequest.apiFormat(sess),
177181
Repository: issue.Repo.innerAPIFormat(sess, mode, false),
178182
Sender: doer.APIFormat(),
179183
}

models/issue_mail.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func mailIssueCommentToParticipants(e Engine, issue *Issue, doer *User, content
4848
}
4949

5050
// Assignees must receive any communications
51-
assignees, err := GetAssigneesByIssue(issue)
51+
assignees, err := getAssigneesByIssue(e, issue)
5252
if err != nil {
5353
return err
5454
}

models/issue_user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func newIssueUsers(e Engine, repo *Repository, issue *Issue) error {
5454
func updateIssueAssignee(e *xorm.Session, issue *Issue, assigneeID int64) (removed bool, err error) {
5555

5656
// Check if the user exists
57-
assignee, err := GetUserByID(assigneeID)
57+
assignee, err := getUserByID(e, assigneeID)
5858
if err != nil {
5959
return false, err
6060
}

models/org.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,12 @@ func GetOrgUsersByUserID(uid int64, all bool) ([]*OrgUser, error) {
393393

394394
// GetOrgUsersByOrgID returns all organization-user relations by organization ID.
395395
func GetOrgUsersByOrgID(orgID int64) ([]*OrgUser, error) {
396+
return getOrgUsersByOrgID(x, orgID)
397+
}
398+
399+
func getOrgUsersByOrgID(e Engine, orgID int64) ([]*OrgUser, error) {
396400
ous := make([]*OrgUser, 0, 10)
397-
err := x.
401+
err := e.
398402
Where("org_id=?", orgID).
399403
Find(&ous)
400404
return ous, err

models/repo_watch.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ func notifyWatchers(e Engine, act *Action) error {
113113

114114
switch act.OpType {
115115
case ActionCommitRepo, ActionPushTag, ActionDeleteTag, ActionDeleteBranch:
116-
if !act.Repo.CheckUnitUser(act.UserID, false, UnitTypeCode) {
116+
if !act.Repo.checkUnitUser(e, act.UserID, false, UnitTypeCode) {
117117
continue
118118
}
119119
case ActionCreateIssue, ActionCommentIssue, ActionCloseIssue, ActionReopenIssue:
120-
if !act.Repo.CheckUnitUser(act.UserID, false, UnitTypeIssues) {
120+
if !act.Repo.checkUnitUser(e, act.UserID, false, UnitTypeIssues) {
121121
continue
122122
}
123123
case ActionCreatePullRequest, ActionMergePullRequest, ActionClosePullRequest, ActionReopenPullRequest:
124-
if !act.Repo.CheckUnitUser(act.UserID, false, UnitTypePullRequests) {
124+
if !act.Repo.checkUnitUser(e, act.UserID, false, UnitTypePullRequests) {
125125
continue
126126
}
127127
}

0 commit comments

Comments
 (0)