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 bug with async_lock implementation #2695

Merged
merged 1 commit into from
Oct 31, 2022

Conversation

fselmo
Copy link
Collaborator

@fselmo fselmo commented Oct 26, 2022

What was wrong?

closes #2693

How was it fixed?

  • Properly close async_lock if something goes wrong during a task.

Todo:

Cute Animal Picture

20221026_111149

@fselmo fselmo marked this pull request as ready for review October 26, 2022 18:15
@fselmo fselmo requested review from kclowes and pacrob October 26, 2022 18:18
inner.cancel()

outer = asyncio.create_task(_utilize_async_lock())
await outer
Copy link

@ariel-simnegar ariel-simnegar Oct 26, 2022

Choose a reason for hiding this comment

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

It might be better to replace this line with await asyncio.wait_for(outer, 2) which will raise an asyncio.TimeoutError if outer takes more than 2 more seconds to execute. That way we'll get a failed test rather than a hang if there's a future bug with the lock.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍🏼 good point. I actually tweaked the timeouts quite a bit to make the test faster in general.

@fselmo fselmo force-pushed the async-cache-bug-hotfix branch 2 times, most recently from fe78025 to dc84582 Compare October 26, 2022 19:40
- ``async_lock`` would hold onto the lock even if a task had been cancelled. This change ensures that the lock will be released if an exception is thrown during ``loop.run_in_executor()``.
Copy link
Contributor

@pacrob pacrob left a comment

Choose a reason for hiding this comment

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

lgtm!

Copy link
Collaborator

@kclowes kclowes left a comment

Choose a reason for hiding this comment

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

LGTM! 🚢

@fselmo fselmo merged commit 9f24fb9 into ethereum:master Oct 31, 2022
@fselmo fselmo deleted the async-cache-bug-hotfix branch April 3, 2024 20:50
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.

web3._utils.request.async_lock sometimes incorrectly handles the cancellation of the task it is running in
4 participants