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
…at the same time
  • Loading branch information
gsergey418alt committed Feb 5, 2025
1 parent 7c1f0a3 commit ca1fabf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ The following emojis are used to highlight certain changes:

### Changed

- `provider`: Prevent multiple instances of reprovider.Reprovide() from running at the same time.

### Removed

### Fixed
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")
}

Check warning on line 477 in provider/reprovider.go

View check run for this annotation

Codecov / codecov/patch

provider/reprovider.go#L476-L477

Added lines #L476 - L477 were not covered by tests
defer s.mu.Unlock()

kch, err := s.keyProvider(ctx)
if err != nil {
return err
Expand Down

0 comments on commit ca1fabf

Please sign in to comment.