Skip to content

Commit fdd2dc9

Browse files
authored
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
1 parent d1b9f92 commit fdd2dc9

File tree

2 files changed

+4
-4
lines changed
  • modules/openapi-generator/src/main/resources/python/asyncio
  • samples/openapi3/client/petstore/python-aiohttp/petstore_api

2 files changed

+4
-4
lines changed

modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ class RESTClientObject:
7979
client_session=self.pool_manager,
8080
retry_options=aiohttp_retry.ExponentialRetry(
8181
attempts=retries,
82-
factor=0.0,
83-
start_timeout=0.0,
82+
factor=2.0,
83+
start_timeout=0.1,
8484
max_timeout=120.0
8585
)
8686
)

samples/openapi3/client/petstore/python-aiohttp/petstore_api/rest.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ def __init__(self, configuration) -> None:
8989
client_session=self.pool_manager,
9090
retry_options=aiohttp_retry.ExponentialRetry(
9191
attempts=retries,
92-
factor=0.0,
93-
start_timeout=0.0,
92+
factor=2.0,
93+
start_timeout=0.1,
9494
max_timeout=120.0
9595
)
9696
)

0 commit comments

Comments
 (0)