mollie / mollie-api-python

Mollie API client for Python
http://www.mollie.com
BSD 2-Clause "Simplified" License
113 stars 55 forks source link

Unexpected retry after ReadTimeoutError #325

Closed andreashug closed 1 year ago

andreashug commented 1 year ago

Issue

The client does 9 retry attempts after ReadTimeoutError if retry is set (default). This is contrary to the parameter description which says that only connect errors trigger a retry. According to the API documentation, this behavior might lead to multiple charges of recurring payments if no idempotency key is set.

Steps to Reproduce

import logging
logging.basicConfig(level="WARNING")

client = Client(timeout=(2, 0.1))  # Configure with 0.1 read timeout to simulate actual API timeout
client.set_api_key(...)
client.payments.get(...)

I've tested this with v2.13.0 but the code is the same in master.

Current Behavior

9 retries after ReadTimeoutError

WARNING 2023-06-30 16:10:50 urllib3.connectionpool
Retrying (Retry(total=9, connect=3, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='api.mollie.com', port=443): Read timed out. (read timeout=0.1)")': /v2/payments/tr_xxx

WARNING 2023-06-30 16:10:53 urllib3.connectionpool
Retrying (Retry(total=8, connect=3, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='api.mollie.com', port=443): Read timed out. (read timeout=0.1)")': /v2/payments/tr_xxx

[6 more until total reaches 0]

Expected Behavior

No retries after ReadTimeoutError

Possible Implementation

Set read retries to 0 when instantiating urllib3.utils.Retry in mollie/api/client.py

retry = Retry(connect=self.retry, read=0, backoff_factor=1)
whyscream commented 1 year ago

Hello @andreashug , thanks for reporting. This might an error due to misreading the urllib3 documentation. We will look into it.

whyscream commented 1 year ago

@andreashug we just released version 3.4.0 of the library, with your fix to this issue.