#43512·grpc

[Python]: grpc.aio.Channel only registers a multi-kind client interceptor for the first matching RPC kind (unary-unary), silently dropping unary-stream/stream-unary/stream-stream

Author: xbabka01Created Sep 23, 2026Updated Sep 27, 2026
Labelskind/buglang/Pythonpriority/P2

What version of gRPC and what language are you using?

grpcio 1.83.1, Python (grpc.aio asyncio client API).

What operating system (Linux, Windows,...) and version?

macOS (Darwin 25.6.0, arm64). The bug is a pure Python logic error and is not platform-specific — it will reproduce identically on Linux/Windows.

What runtime / compiler are you using (e.g. python version or version of gcc)

CPython 3.14.2.

What did you do?

grpc.aio.Channel.__init__ (grpc/aio/_channel.py) sorts the interceptors passed to insecure_channel/secure_channel into four per-RPC-kind lists (_unary_unary_interceptors, _unary_stream_interceptors, _stream_unary_interceptors, _stream_stream_interceptors) using an if/elif chain of isinstance checks, rather than four independent checks:

python
if interceptors is not None:
    for interceptor in interceptors:
        if isinstance(interceptor, UnaryUnaryClientInterceptor):
            self._unary_unary_interceptors.append(interceptor)
        elif isinstance(interceptor, UnaryStreamClientInterceptor):
            self._unary_stream_interceptors.append(interceptor)
        elif isinstance(interceptor, StreamUnaryClientInterceptor):
            self._stream_unary_interceptors.append(interceptor)
        elif isinstance(interceptor, StreamStreamClientInterceptor):
            self._stream_stream_interceptors.append(interceptor)

Each of Channel.unary_unary() / .unary_stream() / .stream_unary() / .stream_stream() only consults its own list when building the interceptor chain for a call. So any interceptor class that implements more than one of the four grpc.aio.*ClientInterceptor ABCs — a very natural thing to do when you want one interceptor (e.g. for auth headers, logging, or metrics) to apply uniformly to every RPC kind — only ever gets registered for the first ABC it matches in the order checked above (unary-unary first), and is silently never invoked for the other RPC kinds.

Minimal, self-contained repro (no server needed — this only inspects how the interceptor gets bucketed at channel-construction time):

python
import grpc.aio as aio


class MultiKindInterceptor(
    aio.UnaryUnaryClientInterceptor,
    aio.UnaryStreamClientInterceptor,
    aio.StreamUnaryClientInterceptor,
    aio.StreamStreamClientInterceptor,
):
    """An interceptor meant to apply to every RPC kind, e.g. to attach an
    auth header to all outgoing calls."""

    async def intercept_unary_unary(self, continuation, client_call_details, request):
        return await continuation(client_call_details, request)

    async def intercept_unary_stream(self, continuation, client_call_details, request):
        return await continuation(client_call_details, request)

    async def intercept_stream_unary(self, continuation, client_call_details, request_iterator):
        return await continuation(client_call_details, request_iterator)

    async def intercept_stream_stream(self, continuation, client_call_details, request_iterator):
        return await continuation(client_call_details, request_iterator)


interceptor = MultiKindInterceptor()

# Sanity check: the interceptor really does implement all four ABCs.
assert isinstance(interceptor, aio.UnaryUnaryClientInterceptor)
assert isinstance(interceptor, aio.UnaryStreamClientInterceptor)
assert isinstance(interceptor, aio.StreamUnaryClientInterceptor)
assert isinstance(interceptor, aio.StreamStreamClientInterceptor)

channel = aio.insecure_channel("localhost:1", interceptors=[interceptor])

print("unary_unary bucket:  ", channel._unary_unary_interceptors)
print("unary_stream bucket: ", channel._unary_stream_interceptors)
print("stream_unary bucket: ", channel._stream_unary_interceptors)
print("stream_stream bucket:", channel._stream_stream_interceptors)

What did you expect to see?

Since interceptor is an instance of all four grpc.aio.*ClientInterceptor ABCs, I expected it to be registered in all four per-kind lists, so that intercept_unary_stream/intercept_stream_unary/intercept_stream_stream are actually invoked when the corresponding RPC kind is called through the channel — matching the behavior of the synchronous grpc.intercept_channel/grpc.Channel, which checks each ABC independently and correctly wires up an interceptor for every kind it implements.

What did you see instead?

unary_unary bucket:   [<__main__.MultiKindInterceptor object at 0x...>]
unary_stream bucket:  []
stream_unary bucket:  []
stream_stream bucket: []

The interceptor is registered only for unary_unary — the first ABC matched by the if/elif chain — and is silently absent from the other three buckets, even though it implements all four interfaces. In a real application this means intercept_unary_stream, intercept_stream_unary, and intercept_stream_stream are never called at all for that interceptor: any per-RPC behavior implemented there (e.g. attaching an auth header on a channel that can't use native CallCredentials, recording metrics, retrying) silently never runs for streaming RPCs, with no warning or error — it just looks like the interceptor logic is being skipped.

We hit this in production via an interceptor that adds a bearer token to outgoing calls on a plaintext channel (a channel credentials aren't usable there, so this is done via an interceptor instead, per the workaround described in #33618). Streaming RPCs over that channel went out with no auth header and were rejected server-side, while unary-unary RPCs on the exact same channel worked fine — which is what led us to this bucketing behavior.

The sync (non-aio) grpc.intercept_channel does not have this problem: it performs an independent isinstance check for each of the four ABCs, so a multi-ABC interceptor is correctly wired up for every kind it implements there.