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

eth/filters: fix potential deadlock in filter timeout loop #22178

Merged
merged 3 commits into from
Jan 21, 2021

Conversation

s1na
Copy link
Contributor

@s1na s1na commented Jan 15, 2021

This PR adds a test reproducing #22131. It fails reliably on my machine but I could increase the tx bombardment time range to increase the odds of hitting the bug.


// Wait until filters have timed out
time.Sleep(250 * time.Millisecond)

Copy link
Contributor

Choose a reason for hiding this comment

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

We should also check that all created filters have actually timed out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah on second thought that comment is misleading. At least one filter will time out but we won't know for sure exactly how many will, because during the unsubscription of one of them the routine will hang.

Should I check to see if at least one has been uninstalled (by checking api.filters length?)

Copy link
Contributor

Choose a reason for hiding this comment

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

If the deadlock does not happen, all filters should be gone after this sleep. We should check this because it's an invariant here. You can check this by running GetFilterChanges for all filters (you'll need to collect their IDs into a slice for that). The GetFilterChanges call should return an error for all of them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. Added the check in the select clause's happy case.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why though? We can always check this, right? Worst case it will produce another error message from the test. It's OK to raise more than one error from a test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right I don't know why my brain couldn't process a test failing twice :)

I just tried this but there's another problem. when a deadlock happens GetFilterChanges also hangs. One option I can think of is to go unsafe and directly read len(api.filters) without taking the lock. Wdyt?

eth/filters: fix typo in comment

eth/filters: make test less order and clock dependent

eth/filters: minor fixes
@s1na
Copy link
Contributor Author

s1na commented Jan 15, 2021

Updated with a possible fix. By the way this issue also affects the block and log filters.

@s1na s1na changed the title eth,eth/filters,les: test pending tx filter deadlock eth,eth/filters,les: fix potential deadlock in filter API's timeout loop Jan 15, 2021
@fjl fjl changed the title eth,eth/filters,les: fix potential deadlock in filter API's timeout loop eth,eth/filters,les: fix potential deadlock in filter API timeout loop Jan 21, 2021
@fjl fjl changed the title eth,eth/filters,les: fix potential deadlock in filter API timeout loop eth/filters: fix potential deadlock in filter API timeout loop Jan 21, 2021
@fjl fjl changed the title eth/filters: fix potential deadlock in filter API timeout loop eth/filters: fix potential deadlock in filter timeout loop Jan 21, 2021
@fjl fjl merged commit c4307a9 into ethereum:master Jan 21, 2021
@fjl fjl added this to the 1.10.0 milestone Jan 21, 2021
@s1na s1na deleted the txfilter-deadlock branch January 21, 2021 13:26
bulgakovk pushed a commit to bulgakovk/go-ethereum that referenced this pull request Jan 26, 2021
JukLee0ira added a commit to JukLee0ira/XDPoSChain that referenced this pull request Jul 11, 2024
JukLee0ira added a commit to JukLee0ira/XDPoSChain that referenced this pull request Jul 23, 2024
JukLee0ira added a commit to JukLee0ira/XDPoSChain that referenced this pull request Aug 3, 2024
gzliudan pushed a commit to XinFinOrg/XDPoSChain that referenced this pull request Aug 3, 2024
wanwiset25 pushed a commit to XinFinOrg/XDPoSChain that referenced this pull request Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants