Skip to content

Commit

Permalink
fix race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
codchen committed Dec 30, 2024
1 parent 55d8c40 commit 1ec1ee8
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions evmrpc/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ func (f *LogFetcher) GetLogsByFilters(ctx context.Context, crit filters.FilterCr
defer wg.Done()
defer func() {
if r := recover(); r != nil {
mu.Lock()
defer mu.Unlock()

Check warning on line 353 in evmrpc/filter.go

View check run for this annotation

Codecov / codecov/patch

evmrpc/filter.go#L352-L353

Added lines #L352 - L353 were not covered by tests
err = fmt.Errorf("unexpected panic caught in GetLogsByFilters worker: %v", r)
}
}()
Expand Down Expand Up @@ -387,16 +389,16 @@ func (f *LogFetcher) GetLogsByFilters(ctx context.Context, crit filters.FilterCr
close(resultsChan) // Close the results channel after workers finish
}()

// Check err after all work is done
if len(errorsList) > 0 {
err = errors.Join(errorsList...)
}

// Aggregate results into the final slice
for result := range resultsChan {
res = append(res, result)
}

// Check err after all work is done
if len(errorsList) > 0 {
err = errors.Join(errorsList...)
}

Check warning on line 400 in evmrpc/filter.go

View check run for this annotation

Codecov / codecov/patch

evmrpc/filter.go#L399-L400

Added lines #L399 - L400 were not covered by tests

// Sorting res in ascending order
sort.Slice(res, func(i, j int) bool {
return res[i].BlockNumber < res[j].BlockNumber
Expand Down

0 comments on commit 1ec1ee8

Please sign in to comment.