fix(client/grpc): use SyncGrpcClient._create_channel in sync paths#5601
Open
alvinttang wants to merge 1 commit intobentoml:mainfrom
Open
fix(client/grpc): use SyncGrpcClient._create_channel in sync paths#5601alvinttang wants to merge 1 commit intobentoml:mainfrom
alvinttang wants to merge 1 commit intobentoml:mainfrom
Conversation
`SyncGrpcClient.from_url` and `SyncGrpcClient.wait_until_server_ready`
called `GrpcClient._create_channel`, but `GrpcClient` is a thin wrapper
that does not define `_create_channel`. Only `SyncGrpcClient` and
`AsyncGrpcClient` do. Every grpc-kind sync client construction crashed
with `AttributeError: type object 'GrpcClient' has no attribute
'_create_channel'` before any network call was attempted.
Fix: route sync code paths through `SyncGrpcClient._create_channel`,
which returns a sync `grpc.{insecure,secure}_channel` compatible with
the surrounding `with` block. The async paths already use the correct
`AsyncGrpcClient._create_channel`.
Adds a unit-level regression test covering both call sites and asserting
that `SyncGrpcClient._create_channel` returns a sync context manager.
Fixes bentoml#4683
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SyncGrpcClient.from_urlandSyncGrpcClient.wait_until_server_readyresolved_create_channelvia the wrapper classGrpcClient, which only composes a sync + async grpc client and does not define_create_channelitself. Every sync-kind grpc client construction therefore raised:before any RPC was attempted. Even if the lookup had fallen back to the async version, that returns
grpc.aio.insecure_channel(...)which only supportsasync with— incompatible with the surrounding syncwithblock.Fixes #4683
Root cause
Only the leaf classes
SyncGrpcClientandAsyncGrpcClientdefine their own static_create_channel.GrpcClient(the wrapper) does not. The two sync paths referencedGrpcClient._create_channeldirectly.Fix
src/bentoml/_internal/client/grpc.py:SyncGrpcClient.from_urlis a@classmethod, so it now usescls._create_channel(...)— that resolves toSyncGrpcClient._create_channelfor the base class and lets subclasses override the channel factory.SyncGrpcClient.wait_until_server_readyis a@staticmethod(nocls), so it now hardcodesSyncGrpcClient._create_channel(...)— same observable behaviour as before, just calling a method that actually exists.Tests
tests/unit/_internal/client/test_grpc_sync_create_channel.py:test_grpc_client_has_no_create_channel— guards against future regressions that re-introduce the missing attribute on the wrapper class.test_sync_grpc_client_create_channel_returns_sync_context_manager— the resolved helper must return a sync context manager.test_wait_until_server_ready_does_not_raise_create_channel_attribute_error—wait_until_server_readymust not raise the originalAttributeErrorwhen the helper is not present on the wrapper.test_from_url_does_not_raise_create_channel_attribute_error— same forfrom_url.Locally on
darwin/arm64:pytest tests/unit/_internal/client/test_grpc_sync_create_channel.py→ 4 passed.ruff checkclean.Risk notes
Two single-line call-site swaps inside
SyncGrpcClient. Async paths already usedAsyncGrpcClient._create_channeland are untouched. No public API change.