Skip to content

Conversation

@fselmo
Copy link
Collaborator

@fselmo fselmo commented May 30, 2024

What was wrong?

Though #3265 is not reproducible, this hopefully closes #3265 as there should be no more conflicts across separate instances due to unique instantiation of session managing per provider.

How was it fixed?

  • Use a unique session manager for each instance of HTTPProvider, and AsyncHTTPProvider, by moving all the shared session cache logic into a class and strapping it to each provider instance.
  • Update tests related to session caching
  • Update docs and update the typing for request_retry_configuration along the way (Optional)

Todo:

  • Clean up commit history
  • Add or update documentation related to these changes
  • Add entry to the release notes

Cute Animal Picture

20240528_215358~2

@fselmo fselmo force-pushed the session-cache-per-instance branch from 05126e5 to ef07dfd Compare May 30, 2024 19:35
@fselmo fselmo changed the title Strap a RequestSessionManager to each instance of http providers Strap a RequestSessionManager to each instance of http providers May 30, 2024
@fselmo fselmo marked this pull request as ready for review May 30, 2024 21:00
@fselmo fselmo requested review from kclowes, pacrob and reedsa May 30, 2024 21:04
@fselmo fselmo force-pushed the session-cache-per-instance branch from f94656d to 1f4e756 Compare May 30, 2024 21:15
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.

The idea of strapping this manager to a provider is cracking me up for some reason. I'm imagining ratchet straps 😆 Aaaanyway, this looks good to me! There wasn't really a good place to put this in the PR, but what do you think about moving the name of web3/_utils/request.py to something like web3/_utils/request_session_manager.py since the RequestSessionManager class is basically all the file has now? Otherwise I left some small nits, but nothing big.

@fselmo
Copy link
Collaborator Author

fselmo commented May 31, 2024

The idea of strapping this manager to a provider is cracking me up for some reason. I'm imagining ratchet straps 😆

😆

Aaaanyway, this looks good to me! There wasn't really a good place to put this in the PR, but what do you think about moving the name of web3/_utils/request.py to something like web3/_utils/request_session_manager.py since the RequestSessionManager class is basically all the file has now? Otherwise I left some small nits, but nothing big.

I think I'll still put the DEFAULT_REQUEST_TIMEOUT here and use it for the CCIP read http requests, which it doesn't matter what provider we are using, it still makes a http GET or POST as part of the spec. For that reason it might make sense to still keep this as request utils? Or should I move the class definition into request_session_manager.py and keep the minimal request.py as a space for adding more than just the DEFAULT_REQUEST_TIMEOUT?

@kclowes
Copy link
Collaborator

kclowes commented May 31, 2024

I think I'll still put the DEFAULT_REQUEST_TIMEOUT here and use it for the CCIP read http requests, which it doesn't matter what provider we are using, it still makes a http GET or POST as part of the spec. For that reason it might make sense to still keep this as request utils? Or should I move the class definition into request_session_manager.py and keep the minimal request.py as a space for adding more than just the DEFAULT_REQUEST_TIMEOUT?

Keeping DEFAULT_REQUEST_TIMEOUT in there sounds good to me, and therefore keeping this as request utils also probably makes the most sense? I wouldn't be opposed to splitting it out either though. Whatever you think!

@fselmo
Copy link
Collaborator Author

fselmo commented May 31, 2024

Keeping DEFAULT_REQUEST_TIMEOUT in there sounds good to me, and therefore keeping this as request utils also probably makes the most sense? I wouldn't be opposed to splitting it out either though. Whatever you think!

Actually, we have a _utils/http.py already... I'm thinking that since this is really only managing HTTP sessions, we rename the class to HTTPSessionManager, create a _utils/http_session_manager.py and put it there, and then move the default timeout to _utils/http.py as HTTP_REQUEST_TIMEOUT. Thoughts there?

@kclowes
Copy link
Collaborator

kclowes commented May 31, 2024

Yeah, I like that. More specific!

@fselmo fselmo force-pushed the session-cache-per-instance branch 2 times, most recently from f8f00df to e6ceb81 Compare May 31, 2024 17:36
@fselmo
Copy link
Collaborator Author

fselmo commented May 31, 2024

Yeah, I like that. More specific!

Sweet. The changes were significant enough. Can I ask for one last pass starting at this commit before we call it done? I also added passing the timeout through to the respective sync and async cache_and_return_session() methods so we can use a more accurate value for triggering the session closing tasks in that method.


edit

Just kidding I had to update the commit hash, should be good now. I added the timeout check to the integrations tests as well.

- ``RequestSessionManager`` -> ``HTTPSessionManager``
- Move default timeout for http from ``_utils/request.py`` -> ``_utils/http.py``.
  This eliminates the need for a ``request.py`` utils since ``HTTPSessionManager``
  lives in its own file at ``_utils/http_session_manager.py```.
- Pass the configured timeout to sync and async ``cache_and_return_session`` methods.
  Previously, we were using the hard-coded default value and if the call is
  coming from a provider (99% of the time), rather than the request method
  being invoked directly, we would be using the wrong value when spinning off
  any session closing tasks.
@fselmo fselmo force-pushed the session-cache-per-instance branch from e6ceb81 to f9352e0 Compare May 31, 2024 17:42
@fselmo fselmo force-pushed the session-cache-per-instance branch from 6b8486f to 78df3fc Compare June 3, 2024 17:46
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.

I left one comment about a None check, but other than that, looks good!

@fselmo fselmo force-pushed the session-cache-per-instance branch from c5c8043 to 6cf1859 Compare June 5, 2024 17:39
- Improve the async session closing by utilizing a non-blocking asyncio
  ``Task``.
@fselmo fselmo force-pushed the session-cache-per-instance branch from 6cf1859 to aade88f Compare June 5, 2024 18:10
@fselmo fselmo merged commit b30d7d5 into ethereum:main Jun 5, 2024
@fselmo fselmo deleted the session-cache-per-instance branch June 5, 2024 18:35
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.

response is ERROR when using 'multiprocessing'

3 participants