GoogleCloudPlatform / cloud-sql-nodejs-connector

A JavaScript library for connecting securely to your Cloud SQL instances
Apache License 2.0
66 stars 8 forks source link

fix: only retry 5xx Cloud SQL Admin API errors #375

Closed jackwotherspoon closed 1 month ago

jackwotherspoon commented 1 month ago

This commit fixes the retry behavior of the two SQL Admin API calls.

Any response that results in a 50x error will now be retried up to 5 times with exponential backoff. Using gaxios default exponential backoff.

Previously the Node Connector was only retrying 3 times and for all error codes.

Updating gaxios version to have newer params available.

Fixes #371

enocom commented 1 month ago

How does this affect the range of best case to worst case in terms of time taken?

jackwotherspoon commented 1 month ago

How does this affect the range of best case to worst case in terms of time taken?

I can look at calculating it, the formula used by default is found here:

https://github.com/googleapis/gaxios/blob/main/src/retry.ts#L178

jackwotherspoon commented 1 month ago

Did a test and got the following delays:

Retry attempts and delay in ms

Attempt 0:  200
Attempt 1:  310
Attempt 2:  810
Attempt 3:  1620
Attempt 4:  2930
enocom commented 1 month ago

Thanks, Jack. LGTM.