Skip to content

Commit

Permalink
Remove EsnureClosed
Browse files Browse the repository at this point in the history
  • Loading branch information
dimriou committed Nov 28, 2023
1 parent f2dc3b3 commit d5b3da0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
12 changes: 7 additions & 5 deletions common/txmgr/txmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 0 additions & 11 deletions core/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"math"
"math/big"
mrand "math/rand"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d5b3da0

Please sign in to comment.