From fdd2dc9651d141c6d84e068645628c59b298037a Mon Sep 17 00:00:00 2001 From: Gergely Imreh Date: Mon, 12 Aug 2024 17:35:00 +0800 Subject: [PATCH] python-asyncio: update retry factors for actual exponential retries (#19337) * python-asyncio: update retry factors for actual exponential retries As per the `aiohttp-retry` library's code[^1], the timeout is ```python timeout = self._start_timeout * (self._factor ** attempt) ``` This means the previous setting with "start_timeout=0.0" would have always just retried right away (0 timeout) regardless of the "factor" value, and also, "factor=0.0" would never have increased the timeout, rather it would have resulted in a 0 timeout regardless of the value of "start_timeout". This double-zeroing effectively rendered exponential backoff to nothing (rather than "retries" number of retries in quick succession. The update is a quick fix to set the same default as in `aiohttp-retry`. In the future this should likely be configurable (through extra Configuration settings perhaps?), as not all APIs are created equal, but this works as a quick fix for making retries more effective. [^1]: https://github.com/inyutin/aiohttp_retry/blob/ba2169891f5b32a5c59e48ca185dd8e68e44ded7/aiohttp_retry/retry_options.py#L38-L65 * updated example --- .../src/main/resources/python/asyncio/rest.mustache | 4 ++-- .../client/petstore/python-aiohttp/petstore_api/rest.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache b/modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache index edfcc66727e..c3f8643687a 100644 --- a/modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache +++ b/modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache @@ -79,8 +79,8 @@ class RESTClientObject: client_session=self.pool_manager, retry_options=aiohttp_retry.ExponentialRetry( attempts=retries, - factor=0.0, - start_timeout=0.0, + factor=2.0, + start_timeout=0.1, max_timeout=120.0 ) ) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/rest.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/rest.py index ffdf1f9d400..53b81b840d2 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/rest.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/rest.py @@ -89,8 +89,8 @@ class RESTClientObject: client_session=self.pool_manager, retry_options=aiohttp_retry.ExponentialRetry( attempts=retries, - factor=0.0, - start_timeout=0.0, + factor=2.0, + start_timeout=0.1, max_timeout=120.0 ) )