Skip to content

[Serve] Route grpcio 1.84 registered handlers through proxy - #66494

Closed
XFDG wants to merge 1 commit into
ray-project:masterfrom
XFDG:fix/ray-grpc-registered-handlers-66493
Closed

XFDG wants to merge 1 commit into
ray-project:masterfrom
XFDG:fix/ray-grpc-registered-handlers-66493

Conversation

@XFDG

@XFDG XFDG commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Tests

  • Targeted grpc utility tests: 4 passed, 11 deselected (grpcio 1.84.0).
  • Loopback aio gRPC smoke test: registered handler routed through the Serve factory rather than the mock servicer.

@XFDG
XFDG requested a review from a team as a code owner September 25, 2026 15:39

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the gRPC server utility by extracting the method handler override logic into a helper method and adding support for routing registered-method handlers through Ray Serve via add_registered_method_handlers. It also adds corresponding unit tests. The review feedback correctly identifies that add_registered_method_handlers is only supported in newer versions of grpcio (1.62.0+). To avoid compatibility issues and test failures on older versions, it is recommended to check for the existence of this method on the superclass before calling it, and to conditionally skip the new unit tests using @pytest.mark.skipif.

Comment on lines +123 to +127
def add_registered_method_handlers(self, service_name: str, method_handlers):
"""Route grpcio's registered-method handlers through Serve as well."""
if service_name in self._passthrough_service_names:
super().add_registered_method_handlers(service_name, method_handlers)
return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The add_registered_method_handlers method is only available in newer versions of grpcio (1.62.0+). Since Ray supports older versions of grpcio, calling super().add_registered_method_handlers directly will raise an AttributeError on environments with older grpcio installed. We should check if the superclass has this attribute before proceeding, and raise a clear AttributeError if it is missing.

    def add_registered_method_handlers(self, service_name: str, method_handlers):
        """Route grpcio's registered-method handlers through Serve as well."""
        if not hasattr(super(), "add_registered_method_handlers"):
            raise AttributeError(
                "The underlying grpcio library does not support add_registered_method_handlers."
            )

        if service_name in self._passthrough_service_names:
            super().add_registered_method_handlers(service_name, method_handlers)
            return

)


def test_grpc_server_overrides_registered_method_handlers(monkeypatch):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

On older versions of grpcio where Server does not have add_registered_method_handlers, monkeypatch.setattr will raise an AttributeError and fail the test suite. We should skip this test if the installed grpcio version does not support this method.

@pytest.mark.skipif(
    not hasattr(Server, "add_registered_method_handlers"),
    reason="grpcio version does not support add_registered_method_handlers",
)
def test_grpc_server_overrides_registered_method_handlers(monkeypatch):

assert handler.stream_stream() == f"stream_stream call from {service_method}".encode()


def test_grpc_server_registered_passthrough_handlers_are_unchanged(monkeypatch):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similarly, this test should be skipped on older versions of grpcio where Server does not have add_registered_method_handlers to prevent monkeypatch.setattr from raising an AttributeError.

@pytest.mark.skipif(
    not hasattr(Server, "add_registered_method_handlers"),
    reason="grpcio version does not support add_registered_method_handlers",
)
def test_grpc_server_registered_passthrough_handlers_are_unchanged(monkeypatch):

@qishengxhe

Copy link
Copy Markdown
Contributor

@XFDG microcheck is failing on lint. dco is failing too, because the commit has no sign-off.

note for the serve team (separate from this PR): CI installs with requirements_compiled.txt, which pins grpcio to 1.75/1.76. setup.py leaves grpcio unbounded, so users get 1.84 while CI never runs it, and that's how this slipped through. It might be worth running at least the Serve gRPC tests against the latest grpcio so a version bump like this gets caught before users hit it.

"""
self._passthrough_service_names.add(service_name)

def _override_method_handler(self, service_method: str, method_handler):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we add types here?

def _override_method_handler(
    self, service_method: str, method_handler: grpc.RpcMethodHandler
) -> grpc.RpcMethodHandler:

self.generic_rpc_handlers.append(generic_rpc_handlers)
super().add_generic_rpc_handlers(generic_rpc_handlers)

def add_registered_method_handlers(self, service_name: str, method_handlers):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: method_handlers: Dict[str, grpc.RpcMethodHandler] to match add_generic_rpc_handlers

def test_grpc_server_registered_passthrough_handlers_are_unchanged(monkeypatch):
registered = {}

def capture_registered_handlers(server, service_name, method_handlers):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this capture setup is duplicated across both tests. Maybe pull it into a fixture?

@ray-gardener ray-gardener Bot added serve Ray Serve Related Issue community-contribution Contributed by the community labels Sep 25, 2026
@XFDG

XFDG commented Sep 26, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #66502. The replacement keeps this PR commit unchanged, adds DCO sign-off on all commits, and includes the grpcio compatibility/review updates.

@XFDG XFDG closed this Sep 26, 2026
abrarsheikh pushed a commit that referenced this pull request Sep 28, 2026
## Summary
- Route grpcio registered-method handlers through the Ray Serve proxy
while preserving passthrough services.
- Gracefully handle grpcio versions without the registered-handler API;
add a fallback test and skip API-specific tests when unavailable.
- Fixes #66493. Supersedes #66494; the original pushed commit was left
unchanged.

## Tests
- Targeted gRPC utility tests: 5 passed, 11 deselected (grpcio 1.84.0).
- Ruff check, Ruff format check, and git diff --check passed.
- The target test module was run with --noconftest because the current
source conftest imports an API absent from the installed Ray wheel.

---------

Signed-off-by: zhaoye <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…6502)

## Summary
- Route grpcio registered-method handlers through the Ray Serve proxy
while preserving passthrough services.
- Gracefully handle grpcio versions without the registered-handler API;
add a fallback test and skip API-specific tests when unavailable.
- Fixes ray-project#66493. Supersedes ray-project#66494; the original pushed commit was left
unchanged.

## Tests
- Targeted gRPC utility tests: 5 passed, 11 deselected (grpcio 1.84.0).
- Ruff check, Ruff format check, and git diff --check passed.
- The target test module was run with --noconftest because the current
source conftest imports an API absent from the installed Ray wheel.

---------

Signed-off-by: zhaoye <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community serve Ray Serve Related Issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Serve] gRPC proxy fails every RPC with grpcio >= 1.84 (registered method handlers bypass gRPCGenericServer)

2 participants