Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(hook): store md5 before sending event to channel #5230

Merged
merged 1 commit into from
Jun 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions engine/hooks/gerrit.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func ListenGerritStreamEvent(ctx context.Context, store cache.Store, v sdk.VCSCo

// Avoid that 2 hook uservice dispatch the same event
// Take the lock to dispatch an event
_, _ = store.Lock(lockKey, time.Minute, 100, 100)
_, _ = store.Lock(lockKey, time.Minute, 100, 10)

// compute md5
hasher := md5.New()
Expand All @@ -329,26 +329,17 @@ func ListenGerritStreamEvent(ctx context.Context, store cache.Store, v sdk.VCSCo
var existString string
b, _ := store.Get(k, &existString)
if !b {
// Dispatch event
gerritEventChan <- event
_ = store.SetWithTTL(k, md5, 300)
}
cpt := 0
for {
if err := store.Unlock(lockKey); err == nil {
break
}
if cpt > 100 {
break
}
log.Warning(ctx, "gerrit> Cannot remove event lock. Retry in 100ms")
time.Sleep(100 * time.Millisecond)
cpt++

// release lock
if err := store.Unlock(lockKey); err == nil {
log.Error(ctx, "unable to unlock %s. Waiting lock timeout", lockKey)
}
if cpt > 100 {
log.Error(ctx, "gerrit> Event lock cannot be removed.")

if !b {
gerritEventChan <- event
}
// release lock
}
}

Expand Down