From 6aa8f03016c5164dd5d135199d4652eef9f15a02 Mon Sep 17 00:00:00 2001 From: Guiheux Steven Date: Mon, 8 Jun 2020 10:08:13 +0200 Subject: [PATCH] fix(hook): store md5 before sending event to channel (#5230) --- engine/hooks/gerrit.go | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/engine/hooks/gerrit.go b/engine/hooks/gerrit.go index d297a1d628..0a7004e403 100644 --- a/engine/hooks/gerrit.go +++ b/engine/hooks/gerrit.go @@ -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() @@ -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 } }