diff --git a/pkg/webhooks/constants/constants.go b/pkg/webhooks/constants/constants.go index 9db968b..f3e87b8 100644 --- a/pkg/webhooks/constants/constants.go +++ b/pkg/webhooks/constants/constants.go @@ -6,5 +6,5 @@ const ( // WebhookHandleTimeout is the duration after which a webhook handle function context times out // the entire thing is asynchronuous anyway, so the VCS will get an immediate response, this is just // that we do not have processing of events hanging internally - WebhookHandleTimeout = 60 * time.Second + WebhookHandleTimeout = 120 * time.Second ) diff --git a/pkg/webhooks/github/actions/aggregate_releases.go b/pkg/webhooks/github/actions/aggregate_releases.go index b513d16..f62c4bd 100644 --- a/pkg/webhooks/github/actions/aggregate_releases.go +++ b/pkg/webhooks/github/actions/aggregate_releases.go @@ -28,6 +28,8 @@ type AggregateReleases struct { repoURL string repoName string pullRequestTitle string + + lock *multilock.Lock } type AggregateReleaseParams struct { @@ -90,6 +92,7 @@ func NewAggregateReleases(logger *zap.SugaredLogger, client *clients.Github, raw repoURL: typedConfig.TargetRepositoryURL, repoName: typedConfig.TargetRepositoryName, pullRequestTitle: pullRequestTitle, + lock: multilock.New(typedConfig.TargetRepositoryName), }, nil } @@ -111,9 +114,8 @@ func (r *AggregateReleases) AggregateRelease(ctx context.Context, p *AggregateRe // preventing concurrent git repo modifications var once sync.Once - lock := multilock.New(r.repoName) - lock.Lock() - defer once.Do(func() { lock.Unlock() }) + r.lock.Lock() + defer once.Do(func() { r.lock.Unlock() }) token, err := r.client.GitToken(ctx) if err != nil { @@ -158,7 +160,7 @@ func (r *AggregateReleases) AggregateRelease(ctx context.Context, p *AggregateRe r.logger.Infow("pushed to aggregate target repo", "target-repo", p.RepositoryName, "source-repo", p.RepositoryName, "release", tag, "branch", r.branch, "hash", hash) - once.Do(func() { lock.Unlock() }) + once.Do(func() { r.lock.Unlock() }) pr, _, err := r.client.GetV3Client().PullRequests.Create(ctx, r.client.Organization(), r.repoName, &v3.NewPullRequest{ Title: v3.String("Next release"), diff --git a/pkg/webhooks/github/actions/distribute_releases.go b/pkg/webhooks/github/actions/distribute_releases.go index c30de85..824272d 100644 --- a/pkg/webhooks/github/actions/distribute_releases.go +++ b/pkg/webhooks/github/actions/distribute_releases.go @@ -117,6 +117,12 @@ func (d *distributeReleases) DistributeRelease(ctx context.Context, p *distribut return errors.Wrap(err, "error creating git token") } + var targetRepos []string + for targetRepoName := range d.targetRepos { + targetRepos = append(targetRepos, targetRepoName) + } + lock := multilock.New(targetRepos...) + g, ctx := errgroup.WithContext(ctx) for targetRepoName, targetRepo := range d.targetRepos { targetRepoName := targetRepoName @@ -132,7 +138,6 @@ func (d *distributeReleases) DistributeRelease(ctx context.Context, p *distribut // preventing concurrent git repo modifications var once sync.Once - lock := multilock.New(targetRepoName) lock.Lock() defer once.Do(func() { lock.Unlock() }) diff --git a/pkg/webhooks/github/actions/yaml_translate_releases.go b/pkg/webhooks/github/actions/yaml_translate_releases.go index 7d3cd04..ecb7ba7 100644 --- a/pkg/webhooks/github/actions/yaml_translate_releases.go +++ b/pkg/webhooks/github/actions/yaml_translate_releases.go @@ -28,6 +28,8 @@ type yamlTranslateReleases struct { repoURL string repoName string pullRequestTitle string + + lock *multilock.Lock } type yamlTranslation struct { @@ -116,6 +118,7 @@ func newYAMLTranslateReleases(logger *zap.SugaredLogger, client *clients.Github, repoURL: typedConfig.TargetRepositoryURL, repoName: typedConfig.TargetRepositoryName, pullRequestTitle: pullRequestTitle, + lock: multilock.New(typedConfig.TargetRepositoryName), }, nil } @@ -137,9 +140,8 @@ func (r *yamlTranslateReleases) translateRelease(ctx context.Context, p *yamlTra // preventing concurrent git repo modifications var once sync.Once - lock := multilock.New(r.repoName, p.RepositoryName) - lock.Lock() - defer once.Do(func() { lock.Unlock() }) + r.lock.Lock() + defer once.Do(func() { r.lock.Unlock() }) token, err := r.client.GitToken(ctx) if err != nil { @@ -207,7 +209,7 @@ func (r *yamlTranslateReleases) translateRelease(ctx context.Context, p *yamlTra r.logger.Infow("pushed to translate target repo", "target-repo", p.RepositoryName, "source-repo", p.RepositoryName, "release", tag, "branch", r.branch, "hash", hash) - once.Do(func() { lock.Unlock() }) + once.Do(func() { r.lock.Unlock() }) pr, _, err := r.client.GetV3Client().PullRequests.Create(ctx, r.client.Organization(), r.repoName, &v3.NewPullRequest{ Title: v3.String("Next release"),