diff --git a/CHANGELOG.md b/CHANGELOG.md index 64de89251..b5064913c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ The following emojis are used to highlight certain changes: ### Changed +- `provider`: Prevent multiple instances of reprovider.Reprovide() from running at the same time. [#834](https://github.com/ipfs/boxo/pull/834) - upgrade to `go-libp2p` [v0.39.0](https://github.com/libp2p/go-libp2p/releases/tag/v0.39.0) ### Removed diff --git a/provider/reprovider.go b/provider/reprovider.go index aeb5a27a5..44a2fea04 100644 --- a/provider/reprovider.go +++ b/provider/reprovider.go @@ -42,6 +42,7 @@ type reprovider struct { ctx context.Context close context.CancelFunc closewg sync.WaitGroup + mu sync.Mutex reprovideInterval time.Duration initalReprovideDelay time.Duration @@ -470,6 +471,12 @@ func (s *reprovider) reprovide(ctx context.Context, force bool) error { return nil } + ok := s.mu.TryLock() + if !ok { + return fmt.Errorf("instance of reprovide already running") + } + defer s.mu.Unlock() + kch, err := s.keyProvider(ctx) if err != nil { return err