From ba222732ef0edf8043329421f116ff3c9412cb02 Mon Sep 17 00:00:00 2001 From: Benj Fassbind Date: Wed, 30 Nov 2022 09:52:47 +0100 Subject: [PATCH] Add api publish mutex At the moment it is posible to have multiple publish updates running at the same time. This is a problem as both processes try to update the same files and some unexpected behaviour might occur. By using a global mutex, only one publish can be updated at any time. --- api/publish.go | 2 ++ context/context.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/api/publish.go b/api/publish.go index 665cebed6..1f2f38be0 100644 --- a/api/publish.go +++ b/api/publish.go @@ -340,6 +340,8 @@ func apiPublishUpdateSwitch(c *gin.Context) { resources = append(resources, string(published.Key())) taskName := fmt.Sprintf("Update published %s (%s): %s", published.SourceKind, strings.Join(updatedComponents, " "), strings.Join(updatedSnapshots, ", ")) maybeRunTaskInBackground(c, taskName, resources, func(out aptly.Progress, detail *task.Detail) (*task.ProcessReturnValue, error) { + context.PublishMutex.Lock() + defer context.PublishMutex.Unlock() err := published.Publish(context.PackagePool(), context, collectionFactory, signer, out, b.ForceOverwrite) if err != nil { return &task.ProcessReturnValue{Code: http.StatusInternalServerError, Value: nil}, fmt.Errorf("unable to update: %s", err) diff --git a/context/context.go b/context/context.go index d80528a54..c6df884e1 100644 --- a/context/context.go +++ b/context/context.go @@ -40,6 +40,7 @@ type AptlyContext struct { flags, globalFlags *flag.FlagSet configLoaded bool + PublishMutex sync.Mutex progress aptly.Progress downloader aptly.Downloader taskList *task.List @@ -593,6 +594,7 @@ func NewContext(flags *flag.FlagSet) (*AptlyContext, error) { var err error context := &AptlyContext{ + PublishMutex: sync.Mutex{}, flags: flags, globalFlags: flags, dependencyOptions: -1,