Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Prevent multiple instances of "ipfs routing reprovide" running together. #834

Merged
merged 3 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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. [#834](https://github.com/ipfs/boxo/pull/834)

### 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 @@
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 @@
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