Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add retry config for UNAVAILABLE errors #93

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions projects/fal/src/fal/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,29 @@ def to_grpc(self) -> grpc.ChannelCredentials:
raise NotImplementedError

@property
def extra_options(self) -> list[tuple[str, str]]:
return GRPC_OPTIONS
def base_options(self) -> dict[str, str | int]:
import json

grpc_ops: dict[str, str | int] = dict(GRPC_OPTIONS)
grpc_ops["grpc.enable_retries"] = 1
grpc_ops["grpc.service_config"] = json.dumps(
{
"methodConfig": [
{
"name": [{}],
"retryPolicy": {
"maxAttempts": 5,
"initialBackoff": "0.1s",
"maxBackoff": "5s",
"backoffMultiplier": 2,
"retryableStatusCodes": ["UNAVAILABLE"],
},
}
]
}
)

return grpc_ops


class LocalCredentials(ServerCredentials):
Expand Down Expand Up @@ -346,10 +367,14 @@ def stub(self) -> isolate_proto.IsolateControllerStub:
if self._stub:
return self._stub

options = self.credentials.server_credentials.extra_options
options = self.credentials.server_credentials.base_options
channel_creds = self.credentials.to_grpc()
channel = self._stack.enter_context(
grpc.secure_channel(self.hostname, channel_creds, options)
grpc.secure_channel(
target=self.hostname,
credentials=channel_creds,
options=list(options.items()),
)
)
channel = grpc.intercept_channel(channel, TraceContextInterceptor())
self._stub = isolate_proto.IsolateControllerStub(channel)
Expand Down
Loading