Skip to content

Commit 06dc686

Browse files
committed
fix data-race
1 parent 6abdcd6 commit 06dc686

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

services/pull/check.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,17 @@ func StartPullRequestCheckDelayable(ctx context.Context, pr *issues_model.PullRe
101101
AddPullRequestToCheckQueue(pr.ID)
102102
}
103103

104-
func StartPullRequestCheckOnView(_ context.Context, pr *issues_model.PullRequest) {
105-
// TODO: its correctness totally depends on the "unique queue" feature.
106-
// So duplicate "start" requests will be ignored if there is already a task in the queue
107-
// Ideally in the future we should decouple the "unique queue" feature from the "start" request
104+
func StartPullRequestCheckOnView(ctx context.Context, pr *issues_model.PullRequest) {
105+
// TODO: its correctness totally depends on the "unique queue" feature and the global lock.
106+
// So duplicate "start" requests will be ignored if there is already a task in the queue or one is running.
107+
// Ideally in the future we should decouple the "unique queue" feature from the "start" request.
108108
if pr.Status == issues_model.PullRequestStatusChecking {
109-
AddPullRequestToCheckQueue(pr.ID)
109+
// When a PR check starts, the task is popped from the queue and the task handler acquires the global lock
110+
// So we need to acquire the global lock here to prevent from duplicate tasks
111+
_, _ = globallock.TryLockAndDo(ctx, getPullWorkingLockKey(pr.ID), func(ctx context.Context) error {
112+
AddPullRequestToCheckQueue(pr.ID) // the queue is a unique queue and won't add the same task again
113+
return nil
114+
})
110115
}
111116
}
112117

0 commit comments

Comments
 (0)