Skip to content

Commit

Permalink
Set all call timeout defaults on providers to 30:
Browse files Browse the repository at this point in the history
- In the HTTP cases, this actually increases the timeout which matches
  the timeouts in some clients (like Geth); closes #1939.
- This commit also sets the persistent connection timeout to be the same
  as the HTTP timeout for a request which seems reasonable and keeps consistency.
  • Loading branch information
fselmo committed Mar 4, 2024
1 parent b79e302 commit 7960c67
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions newsfragments/3262.misc.rst
@@ -0,0 +1 @@
Set all provider default timeouts to ``30``, effectively increasing HTTP timeouts to better match those of certain clients.
8 changes: 4 additions & 4 deletions tests/core/utilities/test_request.py
Expand Up @@ -99,7 +99,7 @@ def test_json_make_get_request(mocker):
assert len(request._session_cache) == 1
cache_key = generate_cache_key(f"{threading.get_ident()}:{TEST_URI}")
session = request._session_cache.get_cache_entry(cache_key)
session.get.assert_called_once_with(TEST_URI, timeout=10)
session.get.assert_called_once_with(TEST_URI, timeout=30)

# Ensure the adapter was created with default values
check_adapters_mounted(session)
Expand All @@ -119,7 +119,7 @@ def test_make_post_request_no_args(mocker):
assert len(request._session_cache) == 1
cache_key = generate_cache_key(f"{threading.get_ident()}:{TEST_URI}")
session = request._session_cache.get_cache_entry(cache_key)
session.post.assert_called_once_with(TEST_URI, data=b"request", timeout=10)
session.post.assert_called_once_with(TEST_URI, data=b"request", timeout=30)

# Ensure the adapter was created with default values
check_adapters_mounted(session)
Expand Down Expand Up @@ -267,7 +267,7 @@ async def test_async_json_make_get_request(mocker):
session.get.assert_called_once_with(
TEST_URI,
timeout=ClientTimeout(
total=10, connect=None, sock_read=None, sock_connect=None
total=30, connect=None, sock_read=None, sock_connect=None
),
)
await session.close()
Expand All @@ -289,7 +289,7 @@ async def test_async_make_post_request(mocker):
TEST_URI,
data=b"request",
timeout=ClientTimeout(
total=10, connect=None, sock_read=None, sock_connect=None
total=30, connect=None, sock_read=None, sock_connect=None
),
)
await session.close()
Expand Down
4 changes: 2 additions & 2 deletions web3/_utils/module_testing/module_testing_utils.py
Expand Up @@ -104,7 +104,7 @@ def _mock_specific_request(

# mock response only to specified url while validating appropriate fields
if url_from_args == mocked_request_url:
assert kwargs["timeout"] == 10
assert kwargs["timeout"] == 30
if http_method.upper() == "POST":
assert kwargs["data"] == {"data": calldata, "sender": sender}
return MockedResponse()
Expand Down Expand Up @@ -154,7 +154,7 @@ async def _mock_specific_request(

# mock response only to specified url while validating appropriate fields
if url_from_args == mocked_request_url:
assert kwargs["timeout"] == ClientTimeout(10)
assert kwargs["timeout"] == ClientTimeout(30)
if http_method.upper() == "post":
assert kwargs["data"] == {"data": calldata, "sender": sender}
return AsyncMockedResponse()
Expand Down
2 changes: 1 addition & 1 deletion web3/_utils/request.py
Expand Up @@ -35,7 +35,7 @@

logger = logging.getLogger(__name__)

DEFAULT_TIMEOUT = 10
DEFAULT_TIMEOUT = 30


def get_default_http_endpoint() -> URI:
Expand Down
2 changes: 1 addition & 1 deletion web3/providers/ipc.py
Expand Up @@ -130,7 +130,7 @@ class IPCProvider(JSONBaseProvider):
def __init__(
self,
ipc_path: Union[str, Path] = None,
timeout: int = 10,
timeout: int = 30,
*args: Any,
**kwargs: Any,
) -> None:
Expand Down
2 changes: 1 addition & 1 deletion web3/providers/legacy_websocket.py
Expand Up @@ -37,7 +37,7 @@
)

RESTRICTED_WEBSOCKET_KWARGS = {"uri", "loop"}
DEFAULT_WEBSOCKET_TIMEOUT = 10
DEFAULT_WEBSOCKET_TIMEOUT = 30


def _start_event_loop(loop: asyncio.AbstractEventLoop) -> None:
Expand Down
2 changes: 1 addition & 1 deletion web3/providers/persistent/persistent.py
Expand Up @@ -24,7 +24,7 @@
RPCResponse,
)

DEFAULT_PERSISTENT_CONNECTION_TIMEOUT = 50.0
DEFAULT_PERSISTENT_CONNECTION_TIMEOUT = 30.0


class PersistentConnectionProvider(AsyncJSONBaseProvider, ABC):
Expand Down

0 comments on commit 7960c67

Please sign in to comment.