Closed controldev closed 5 months ago
Hey,
Thanks for reaching out, and apologies for the late response.
I'm wondering if this is due to our built-in retries.
Can you try altering the retry settings; that may lower the wait time that causes the gunicorn timeout.
For reference, the retry settings (with default values) at the client level are:
klaviyo = KlaviyoAPI("YOUR_API_KEY_HERE", max_delay=60, max_retries=3)
where max_delay
is the total delay across all retry attempts.
If you'd like to turn off retries altogether and implement your own error handling, you can set:
klaviyo = KlaviyoAPI("YOUR_API_KEY_HERE", max_delay=0, max_retries=0)
hey @jon-batscha - qq regarding retries mechanism - on what status codes does the library makes retries?
we occasionally get 502 responses (like once a day, usually multiple of those at the same time) from the klaviyo api, and not sure if the client library makes a retry on those.
seems to us that it does not and wanted to double check that with you...
also, we would like to use the _request_timeout
variable to use that and i'm not sure how does that combines with the max_delay
and max_retry
when setting the API class.
last time we saw this was around 23:00 UTC time Aug 28th.. example of error response we see in our logs (seems also something with cloudflare?)
Hi Oded,
Thanks for reaching out, great question!
I actually just updated the retry logic in today’s release (thanks to your feedback), so what I’ll describe below applies to versions 5.3.0 and later: we retry on the following error codes:
_STATUS_CODE_CONNECTION_RESET_BY_PEER = 104
_STATUS_CODE_TOO_MANY_REQUESTS = 429
_STATUS_CODE_SERVICE_UNAVAILABLE = 503
_STATUS_CODE_GATEWAY_TIMEOUT = 504
_STATUS_CODE_A_TIMEOUT_OCCURED = 524
NOTE: we do not retry on 502 errors, as those are not guaranteed to be transient, and so retrying on those could hold up jobs. That said, our API team is aware of the occasional 502s and is working to fix this on our end (at the API-level).
In terms of the retry logic: we currently take the following 2 params:
max_delay
max_retries
We retry up to max_retries
, using the following algorithm: wait_random_exponential
The algorithm starts with a 1 second wait, and at each retry, doubles the wait time, up to max_delay
Given this updated logic, we now recommend the following default values (now reflected in our defaults/readme:
max_delay = 60
max_retries = 7
With this setting, the SDK will behave as follows:
At this point, if no success, we’ll stop retrying.
You can find the code that implements retry logic and sets retry codes here.
Hopefully this answers your question. Please do not hesitate to reach out if you run into any further issues.
(I also received your email yesterday, will follow up on the questions you sent over there in a bit)
closing this issue as it has been inactive for ~ 6 months
Hi there,
I noticed that, starting about 1-2 weeks ago, about one every 10-20 requests (roughly 5-10% of calls) made using the Klaviyo API for Python hang and cause my containing Django app to timeout.
I'm using
klaviyo-api==2.0.0
inside a Django 3.2.11 app, which runs on apython:3.8-slim-buster
with no further modifications made.This is an issue exclusive to calls made to Klaviyo and I've excluded any connectivity issues on my side.
Any ideas, fixes or workarounds would be highly appreciated. Let me know if there is any other information I can provide.
Below is a stack trace for calls made to
Profiles.create_profile()
, the program is stuck onreturn self._sslobj.read(len, buffer)
until thegunicorn
timeout is hit: