Skip to content

Commit 68bef8f

Browse files
authored
[v0.15] - Adds a temporary fix to avoid race conditions when processing webhooks (#4854)
* [v0.15] - Adds a temporary fix to avoid race conditions when processing webhooks Looks like after a recent Github API upgrade commits in a ref are updating slower. We're hitting a race condition between the commit received from a webhook and the commit we get from the ref (because in the ref we get sometimes the previous commit - it takes longer to be reflected) This is a temporary workaround to give time to the ref to be updated. Refers to: #4853 Signed-off-by: Xavi Garcia <xavi.garcia@suse.com> * Add context cancelled verification Signed-off-by: Xavi Garcia <xavi.garcia@suse.com> --------- Signed-off-by: Xavi Garcia <xavi.garcia@suse.com>
1 parent a72317d commit 68bef8f

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

pkg/git/remote.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,6 @@ func (r *Remote) LatestBranchCommit(ctx context.Context, branch string) (string,
138138
return "", err
139139
}
140140

141-
// check if the url is one of the supported for getting the last commit with a specific commits url
142-
commitsURL := getVendorCommitsURL(r.URL, branch)
143-
if commitsURL != "" {
144-
// it is supported. Get the last commit with the vendor's url
145-
// (this is faster than running a whole ls-remote like operation)
146-
if commit, err := latestCommitFromCommitsURL(ctx, commitsURL, r.Options); err == nil {
147-
// in case of error it tries the full List operation
148-
return commit, nil
149-
}
150-
}
151-
152141
refBranch := formatRefForBranch(branch)
153142

154143
refs, err := r.Lister.List(false)

pkg/webhook/webhook.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,18 @@ func (w *Webhook) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
166166
w.logAndReturn(rw, err)
167167
return
168168
}
169+
if gitRepoFromCluster.Spec.DisablePolling {
170+
// if polling is disabled, we add a small sleep to avoid potential race conditions between
171+
// the webhook processing and the reconciliation that happens after the gitrepo update
172+
// Refers to: https://github.com/rancher/fleet/issues/4837
173+
select {
174+
case <-time.After(1 * time.Second):
175+
case <-ctx.Done():
176+
// stop waiting if the request context has been canceled
177+
w.logAndReturn(rw, ctx.Err())
178+
return
179+
}
180+
}
169181
orig := gitRepoFromCluster.DeepCopy()
170182
gitRepoFromCluster.Status.WebhookCommit = revision
171183
// if PollingInterval is not set and webhook is configured, set it to 1 hour

0 commit comments

Comments
 (0)