From c0dbae837f189acc77a23a83a32b4c125f955303 Mon Sep 17 00:00:00 2001 From: Adrien CABARBAYE Date: Thu, 28 Aug 2025 11:15:49 +0100 Subject: [PATCH] :bug: [parallelisation] Revert the behaviour change of close stores introduced in recent release --- changes/20250828111444.bugfix | 1 + utils/parallelisation/group.go | 7 +++++++ utils/parallelisation/onclose.go | 28 ++++++++++++++++++++-------- 3 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 changes/20250828111444.bugfix diff --git a/changes/20250828111444.bugfix b/changes/20250828111444.bugfix new file mode 100644 index 0000000000..f65df39031 --- /dev/null +++ b/changes/20250828111444.bugfix @@ -0,0 +1 @@ +:bug: [parallelisation] Revert the behaviour change of close stores introduced in recent release diff --git a/utils/parallelisation/group.go b/utils/parallelisation/group.go index a7310641d6..a687c913ea 100644 --- a/utils/parallelisation/group.go +++ b/utils/parallelisation/group.go @@ -52,6 +52,13 @@ func (o *StoreOptions) MergeWithOptions(opt ...StoreOption) *StoreOptions { return o.Merge(WithOptions(opt...)) } +func (o *StoreOptions) Apply(opt StoreOption) *StoreOptions { + if opt == nil { + return o + } + return opt(o) +} + func (o *StoreOptions) Overwrite(opts *StoreOptions) *StoreOptions { return o.Default().Merge(opts) } diff --git a/utils/parallelisation/onclose.go b/utils/parallelisation/onclose.go index 39079730c2..9293425859 100644 --- a/utils/parallelisation/onclose.go +++ b/utils/parallelisation/onclose.go @@ -25,11 +25,12 @@ func (s *CloserStore) Len() int { // NewCloserStore returns a store of io.Closer object which will all be closed concurrently on Close(). The first error received will be returned func NewCloserStore(stopOnFirstError bool) *CloserStore { - option := ExecuteAll - if stopOnFirstError { - option = StopOnFirstError - } - return NewCloserStoreWithOptions(option, Parallel, OnlyOnce, RetainAfterExecution) + return NewCloserStoreWithOptions(closeDefaultOptions(stopOnFirstError).Options()...) +} + +// NewCloserOnceStore is similar to NewCloserStore but only close the closers once. +func NewCloserOnceStore(stopOnFirstError bool) *CloserStore { + return NewCloserStoreWithOptions(closeDefaultOptions(stopOnFirstError).Apply(OnlyOnce).Options()...) } // NewCloserStoreWithOptions returns a store of io.Closer object which will all be closed on Close(). The first error received if any will be returned @@ -177,11 +178,22 @@ func NewCloseFunctionStoreStore(stopOnFirstError bool) *CloseFunctionStore { // NewConcurrentCloseFunctionStore returns a store closing functions which will all be called concurrently on Close(). The first error received will be returned. // Prefer using NewCloseFunctionStore where possible func NewConcurrentCloseFunctionStore(stopOnFirstError bool) *CloseFunctionStore { - option := ExecuteAll + return NewCloseFunctionStore(closeDefaultOptions(stopOnFirstError).Options()...) +} + +// NewConcurrentCloseOnceFunctionStore returns a store closing functions once on Close(). It is similar to NewConcurrentCloseFunctionStore otherwise. +func NewConcurrentCloseOnceFunctionStore(stopOnFirstError bool) *CloseFunctionStore { + return NewCloseFunctionStore(closeDefaultOptions(stopOnFirstError).Apply(OnlyOnce).Options()...) +} + +func closeDefaultOptions(stopOnFirstError bool) *StoreOptions { + opts := WithOptions(Parallel, RetainAfterExecution) if stopOnFirstError { - option = StopOnFirstError + opts = opts.Apply(StopOnFirstError) + } else { + opts = opts.Apply(ExecuteAll) } - return NewCloseFunctionStore(option, Parallel, RetainAfterExecution, OnlyOnce) + return opts } // NewCloseOnceGroup is the same as NewCloseFunctionStore but ensures any closing functions are only executed once.