mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-28 12:03:33 +00:00
chore: enable gRPC auto retries for transient Unavailable failures up to ~8s
This commit is contained in:
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user