Skip to content

Commit 5ee2abc

Browse files
authored
feat: Prevent multiple instances of "ipfs routing reprovide" running together. (#834)
* feat: Prevent multiple instances of "ipfs routing reprovide" running at the same time
1 parent 9e4f046 commit 5ee2abc

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The following emojis are used to highlight certain changes:
1818

1919
### Changed
2020

21+
- `provider`: Prevent multiple instances of reprovider.Reprovide() from running at the same time. [#834](https://github.com/ipfs/boxo/pull/834)
2122
- upgrade to `go-libp2p` [v0.39.0](https://github.com/libp2p/go-libp2p/releases/tag/v0.39.0)
2223

2324
### Removed

provider/reprovider.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type reprovider struct {
4242
ctx context.Context
4343
close context.CancelFunc
4444
closewg sync.WaitGroup
45+
mu sync.Mutex
4546

4647
reprovideInterval time.Duration
4748
initalReprovideDelay time.Duration
@@ -470,6 +471,12 @@ func (s *reprovider) reprovide(ctx context.Context, force bool) error {
470471
return nil
471472
}
472473

474+
ok := s.mu.TryLock()
475+
if !ok {
476+
return fmt.Errorf("instance of reprovide already running")
477+
}
478+
defer s.mu.Unlock()
479+
473480
kch, err := s.keyProvider(ctx)
474481
if err != nil {
475482
return err

0 commit comments

Comments
 (0)