chore: enable gRPC auto retries for transient Unavailable failures up to ~8s

This commit is contained in:
Pasha Sviderski
2025-12-23 18:54:08 +10:00
parent aa71ab0220
commit 4d97c30a9c
6 changed files with 35 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
package connector
import (
"encoding/json"
"fmt"
)
// defaultServiceConfig defines the default gRPC service configuration including retry policy for transient failures.
var defaultServiceConfig = mustMarshalJSON(map[string]any{
"methodConfig": []map[string]any{
{
"name": []map[string]string{{"service": ""}},
"retryPolicy": map[string]any{
"maxAttempts": 5, // 5 is the maximum allowed by gRPC
"initialBackoff": "0.5s",
"maxBackoff": "5s",
"backoffMultiplier": 2,
"retryableStatusCodes": []string{"UNAVAILABLE"},
},
},
},
})
func mustMarshalJSON(v any) string {
b, err := json.Marshal(v)
if err != nil {
panic(fmt.Sprintf("failed to marshal service config: %v", err))
}
return string(b)
}