From d5b3da0fcbf3fb82bedae89c0e48b9c02d65a4e1 Mon Sep 17 00:00:00 2001 From: Dimitris Date: Tue, 28 Nov 2023 12:27:57 +0200 Subject: [PATCH] Remove EsnureClosed --- common/txmgr/txmgr.go | 12 +++++++----- core/utils/utils.go | 11 ----------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/common/txmgr/txmgr.go b/common/txmgr/txmgr.go index b49c2b72f15..7b861920101 100644 --- a/common/txmgr/txmgr.go +++ b/common/txmgr/txmgr.go @@ -389,12 +389,14 @@ func (b *Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) runLoop() // be in an Unstarted state here, if execReset exited early. // // In this case, we don't care about stopping them since they are - // already "stopped", hence the usage of utils.EnsureClosed. - if err := utils.EnsureClosed(b.broadcaster); err != nil { - b.logger.Panicw(fmt.Sprintf("Failed to Close Broadcaster: %v", err), "err", err) + // already "stopped". + err := b.broadcaster.Close() + if err != nil && (!errors.Is(err, services.ErrAlreadyStopped) || !errors.Is(err, services.ErrCannotStopUnstarted)) { + b.logger.Errorw(fmt.Sprintf("Failed to Close Broadcaster: %v", err), "err", err) } - if err := utils.EnsureClosed(b.confirmer); err != nil { - b.logger.Panicw(fmt.Sprintf("Failed to Close Confirmer: %v", err), "err", err) + err = b.confirmer.Close() + if err != nil && (!errors.Is(err, services.ErrAlreadyStopped) || !errors.Is(err, services.ErrCannotStopUnstarted)) { + b.logger.Errorw(fmt.Sprintf("Failed to Close Confirmer: %v", err), "err", err) } return case <-keysChanged: diff --git a/core/utils/utils.go b/core/utils/utils.go index 69597fb9e4a..0df280775b5 100644 --- a/core/utils/utils.go +++ b/core/utils/utils.go @@ -9,7 +9,6 @@ import ( "encoding/json" "errors" "fmt" - "io" "math" "math/big" mrand "math/rand" @@ -771,16 +770,6 @@ var ( // Deprecated: use services.StateMachine type StartStopOnce = services.StateMachine -// EnsureClosed closes the io.Closer, returning nil if it was already -// closed or not started yet -func EnsureClosed(c io.Closer) error { - err := c.Close() - if errors.Is(err, ErrAlreadyStopped) || errors.Is(err, ErrCannotStopUnstarted) { - return nil - } - return err -} - // WithJitter adds +/- 10% to a duration func WithJitter(d time.Duration) time.Duration { // #nosec