From cf4cf58faf2285b2752ca47e4f0da2a1e209e0a0 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Wed, 20 Apr 2022 14:18:21 +0100 Subject: [PATCH] Do not allow parallel upgrade in one server (#14782) It is wasteful to allow parallel upgrades of MinIO server. This also generates weird error invoked by selfupdate module when it happens such as: 'rename /opt/bin/.minio.old /opt/bin/..minio.old.old' --- cmd/update.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/update.go b/cmd/update.go index 5239ee4d1..3b620ea83 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -33,6 +33,7 @@ import ( "path/filepath" "runtime" "strings" + "sync/atomic" "time" xhttp "github.com/minio/minio/internal/http" @@ -515,7 +516,14 @@ func getUpdateReaderFromURL(u *url.URL, transport http.RoundTripper, mode string return resp.Body, nil } +var updateInProgress uint32 + func doUpdate(u *url.URL, lrTime time.Time, sha256Sum []byte, releaseInfo string, mode string) (err error) { + if !atomic.CompareAndSwapUint32(&updateInProgress, 0, 1) { + return errors.New("update already in progress") + } + defer atomic.StoreUint32(&updateInProgress, 0) + transport := getUpdateTransport(30 * time.Second) var reader io.ReadCloser if u.Scheme == "https" || u.Scheme == "http" {