Skip to content

Commit

Permalink
feat: Prevent multiple instances of "ipfs routing reprovide" running …
Browse files Browse the repository at this point in the history
…together. (#834)

* feat: Prevent multiple instances of "ipfs routing reprovide" running at the same time
  • Loading branch information
gsergey418alt authored Feb 11, 2025
1 parent 9e4f046 commit 5ee2abc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions provider/reprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5ee2abc

Please sign in to comment.