-
Notifications
You must be signed in to change notification settings - Fork 40
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
Make rpc calls using an asyncio task context MOD-3632 #2178
Conversation
Instead of translating the grpc stubs dynamically, we might want to generate our own stub code using a plugin. It's pretty sparsely documented but should be doable: https://medium.com/cloud-native-daily/create-and-run-a-protobuf-plugin-9471e16e8ad Might be a bit cleaner in terms of tracebacks etc, and could let us do some other things too (i.e. enable retries and handle grpc exceptions more cleanly) |
Do you mean like a fork of grpclib's stub generator (https://github.com/vmagamedov/grpclib/blob/master/grpclib/plugin/main.py) or more like an additional generated stub that references the original? Feels like it would be nice to avoid forking/patching, so we can take advantage of potential improvements in grpclib itself, so maybe the latter? |
yeah no forking right? just an extra plugin |
Yeah exactly - that's what I ended up with, just wanted to clarify that it matched your idea :) |
This reverts commit ff41708.
@@ -145,16 +150,6 @@ async def _close(self, prep_for_restore: bool = False): | |||
# Remove cached client. | |||
self.set_env_client(None) | |||
|
|||
def set_pre_stop(self, pre_stop: Callable[[], Awaitable[None]]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to not be used anymore 🕺
_MetadataLike = Union[Mapping[str, _Value], Collection[Tuple[str, _Value]]] | ||
|
||
|
||
class UnaryUnaryWrapper(Generic[RequestType, ResponseType]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving these to the modal.client
module since they are now tied to a client instance
@prbot approve |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved 👍. @mwaskom will follow-up review this.
)" This reverts commit 0a17fa3.
Wrap all grpc api calls in asyncio.tasks that are cancelled when the Client is closed, and raise a custom error when that happens + for future calls on an already closed Client.
This allows the client to shut down more gracefully by stopping rpc calls prior to unwinding the synchronicity event loop, instead of triggering a generic StreamTerminatedError or similar that we don't know wether to retry or not.