-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add Correct kwargs to AsyncHTTPProvider to allow graceful shutdown #3557
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐑
This looks like this closes the session on every call. Is that what's going on? I think this negates the async session cache altogether. We have some logic that will look in the cache for a session and if it's closed, we have to recreate and replace the stale session. Can we instead introduce this logic somewhere on the provider's garbage collection? Or we could encourage explicit usage of a Thoughts there? |
I would think we have tests for making sure the session is re-used though... maybe I'm off here. But if we don't have these tests, we should add them here as well. |
Looks like we don't have a test like this. This would be good to add. The following test on @pytest.mark.asyncio
async def test_async_http_provider_reuses_cached_session(self, async_w3) -> None:
await async_w3.eth.get_block("latest")
session_cache = async_w3.provider._request_session_manager.session_cache
assert len(session_cache) == 1
session = list(session_cache._data.values())[0]
await async_w3.eth.get_block("latest")
assert len(session_cache) == 1
assert session == list(session_cache._data.values())[0] |
Aha, thanks for taking a look @fselmo. I think only the persistent connection providers have a disconnect method, I'll fix that here. |
@fselmo @kclowes so when I added my comment on the issue #3524, I took a quick look at the code a bit, to see if there was a Perhaps having like a |
0fca0c6
to
a45f4a6
Compare
a45f4a6
to
bc790d0
Compare
Yeah, I came to the same conclusion @alexferl :) This now adds a |
Okay, all fixed. The timeout is actually linked to in the docs, but this issue had an even better fix. Thanks for the assist @fselmo! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
What was wrong?
The session wasn't being properly closed in the AsyncHTTPProvider if there was more than one w3 instance, and warnings were being emitted.
Closes #3524
How was it fixed?
Added an async context manager where needed.
Todo:
Cute Animal Picture