snowflakedb / snowflake-connector-python

Snowflake Connector for Python
https://pypi.python.org/pypi/snowflake-connector-python/
Apache License 2.0
600 stars 473 forks source link

SNOW-635269: Allow control of retry counts and/or retry backoff logic #1207

Open davidemerritt opened 2 years ago

davidemerritt commented 2 years ago

What is the current behavior?

The retry behavior when snowflake responds with a 503 is not controllable. It currently retries 10 times with a jittered 15s backoff.

What is the desired behavior?

Being able to control this either via a global override or the client connection option would be desirable. This would allow for our application logic to handle these errors or do longer backoffs so we don't send barrage the service with more requests when it can't respond.

How would this improve snowflake-connector-python?

Add more configuration and flexibility to the python client.

References, Other Background

Please expose configuration for MAX_DOWNLOAD_RETRY and DecorrelateJitterBackoff

tekumara commented 3 months ago

Retry backoff logic can be set by providing a backoff_policy on connection. The default backoff policy is exponential backoff: https://github.com/snowflakedb/snowflake-connector-python/blob/91aa0fcd23c1d87d069cd9989963c8fbcd1091cf/src/snowflake/connector/connection.py#L183

Retries will occur (with timing determined by the backoff policy) until the timeout is hit. But there is no default timeout, so retries will continue forever unless a network_timeout is provided on connection or a timeout during execute:

https://github.com/snowflakedb/snowflake-connector-python/blob/91aa0fcd23c1d87d069cd9989963c8fbcd1091cf/src/snowflake/connector/connection.py#L349

This is used here:

https://github.com/snowflakedb/snowflake-connector-python/blob/91aa0fcd23c1d87d069cd9989963c8fbcd1091cf/src/snowflake/connector/network.py#L845