Skip to content

Commit fc3693c

Browse files
committed
Docs updates for session caching; exception retry tweaks along the way.
1 parent 714c5ba commit fc3693c

File tree

6 files changed

+44
-7
lines changed

6 files changed

+44
-7
lines changed

docs/internals.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,29 @@ options on the provider instance:
144144
Retry Requests for HTTP Providers
145145
`````````````````````````````````
146146

147+
.. py:class:: web3.providers.rpc.utils.ExceptionRetryConfiguration
148+
149+
.. py:attribute:: errors
150+
151+
A tuple of exceptions that the provider should retry on. The default is
152+
``HTTPProvider``: ``(ConnectionError, requests.HTTPError, requests.Timeout)``
153+
and ``AsyncHTTPProvider``: ``(aiohttp.ClientError, asyncio.TimeoutError)``.
154+
155+
.. py:attribute:: retries
156+
157+
The number of retries to attempt. The default is 5.
158+
159+
.. py:attribute:: backoff_factor
160+
161+
The initial delay multiplier, which doubles with each retry attempt. The default
162+
is 0.125.
163+
164+
.. py:attribute:: method_allowlist
165+
166+
A list of retryable methods. The default is an in-house list of deemed-safe-to-
167+
retry methods.
168+
169+
147170
``HTTPProvider`` and ``AsyncHTTPProvider`` instances retry certain requests by default
148171
on exceptions. This can be configured via configuration options on the provider
149172
instance. The retry mechanism employs an exponential backoff strategy, starting from

docs/providers.rst

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ local and remote JSON-RPC servers.
107107
HTTPProvider
108108
~~~~~~~~~~~~
109109

110-
.. py:class:: web3.providers.rpc.HTTPProvider(endpoint_uri[, request_kwargs, session])
110+
.. py:class:: web3.providers.rpc.HTTPProvider(endpoint_uri, request_kwargs={}, session=None, exception_retry_configuration=ExceptionRetryConfiguration())
111111
112112
This provider handles interactions with an HTTP or HTTPS based JSON-RPC server.
113113

@@ -119,6 +119,11 @@ HTTPProvider
119119
will be passed onto each http/https POST request made to your node.
120120
* ``session`` allows you to pass a ``requests.Session`` object initialized
121121
as desired.
122+
* ``exception_retry_configuration`` is an instance of the
123+
:class:`~web3.providers.rpc.utils.ExceptionRetryConfiguration`
124+
class which allows you to configure how the provider should handle exceptions
125+
when making certain requests. Setting this to ``None`` will disable
126+
exception retries.
122127

123128
.. code-block:: python
124129
@@ -180,7 +185,7 @@ IPCProvider
180185
AsyncHTTPProvider
181186
~~~~~~~~~~~~~~~~~
182187

183-
.. py:class:: web3.providers.async_rpc.AsyncHTTPProvider(endpoint_uri[, request_kwargs])
188+
.. py:class:: web3.providers.rpc.AsyncHTTPProvider(endpoint_uri, request_kwargs={}, exception_retry_configuration=ExceptionRetryConfiguration())
184189
185190
This provider handles interactions with an HTTP or HTTPS based JSON-RPC server asynchronously.
186191

@@ -190,7 +195,14 @@ AsyncHTTPProvider
190195
be omitted from the URI.
191196
* ``request_kwargs`` should be a dictionary of keyword arguments which
192197
will be passed onto each http/https POST request made to your node.
193-
* the ``cache_async_session()`` method allows you to use your own ``aiohttp.ClientSession`` object. This is an async method and not part of the constructor
198+
* ``exception_retry_configuration`` is an instance of the
199+
:class:`~web3.providers.rpc.utils.ExceptionRetryConfiguration`
200+
class which allows you to configure how the provider should handle exceptions
201+
when making certain requests. Setting this to ``None`` will disable
202+
exception retries.
203+
204+
The ``cache_async_session()`` method allows you to use your own
205+
``aiohttp.ClientSession`` object.
194206

195207
.. code-block:: python
196208

newsfragments/3412.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Change the ``exception_retry_configuration`` typing on http providers to be an ``Optional``, as setting this property to ``None`` effectively turns off retries on exceptions for requests.

newsfragments/3412.internal.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use a ``RequestSessionManager`` to manage sessions for http providers, rather than have them share a single session manager / cache.

web3/providers/rpc/async_rpc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ def __init__(
6161
self,
6262
endpoint_uri: Optional[Union[URI, str]] = None,
6363
request_kwargs: Optional[Any] = None,
64-
exception_retry_configuration: Union[
65-
ExceptionRetryConfiguration, Empty
64+
exception_retry_configuration: Optional[
65+
Union[ExceptionRetryConfiguration, Empty]
6666
] = empty,
6767
**kwargs: Any,
6868
) -> None:

web3/providers/rpc/rpc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ def __init__(
6565
endpoint_uri: Optional[Union[URI, str]] = None,
6666
request_kwargs: Optional[Any] = None,
6767
session: Optional[Any] = None,
68-
exception_retry_configuration: Union[
69-
ExceptionRetryConfiguration, Empty
68+
exception_retry_configuration: Optional[
69+
Union[ExceptionRetryConfiguration, Empty]
7070
] = empty,
7171
**kwargs: Any,
7272
) -> None:

0 commit comments

Comments
 (0)