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

fix race condition #2013

Open
wants to merge 1 commit into
base: v6.0.1-hotfix-rpc-8-branch
Choose a base branch
from
Open
Changes from all 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
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 @@
defer wg.Done()
defer func() {
if r := recover(); r != nil {
mu.Lock()
Copy link
Contributor

@yzang2019 yzang2019 Dec 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this being hit at all? I think recover() should never be hit in this logic, and it shouldn't be causing any dead lock issue from my understanding. That being said, adding the lock wouldn't hurt as well

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 @@
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ordering adjustment make sense to me, but I wonder why it would lead to dead lock or stuck issue

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd cause the errorsList = append(errorsList, berr) above to run into undefined behavior which then causes some weirdness

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense to me

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
Loading