grpc / grpc/grpc

[Python] Channelz.GetSocket Exception serializing message when socket id not found

Open
#42,340 0 comments 0 reactions 1 assignee Assigned to @sreenithi View on GitHub
kind/bug lang/Python priority/P2
Dominant language
C++
Stars
45.3k
Forks
11.4k
Avg merge
2d 12h
Merged PRs (30d)
47

Description

### What version of gRPC and what language are you using?
v1.80.x

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

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

### What did you do?
```
docker run --interactive --tty --rm -p 127.0.0.1:8080:8080 --name xdssrv --network my-net us-docker.pkg.dev/grpc-testing/psm-interop/python-server:v1.80.x --port=8080
[INFO tini (1)] Spawned child process '/xds_interop_server' with pid '7'
/xds_interop_server.runfiles/com_google_protobuf/python/google/protobuf/__init__.py:14: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
__import__('pkg_resources').declare_namespace(__name__)
W0508 19:27:49.566791 7 log.cc:110] Log level DEBUG is not suitable for production. Prefer WARNING or ERROR. However if you see this message in a debug environment or test environment it is safe to ignore this message.
E0508 19:27:49.567468 7 trace.cc:86] Unknown tracer: xds_cluster_resolver_lb
I0508 19:27:49.567583 7 trace.cc:91] gRPC Tracers: xds_client, xds_resolver, xds_cluster_manager_lb, cds_lb, priority_lb, xds_cluster_impl_lb, weighted_target_lb
2026-05-08 19:27:49,580: INFO Test server listening on port 8080
2026-05-08 19:27:49,580: INFO Maintenance server listening on port 8080

# serves the grpcurl request for non-existing socket:

2026-05-08 19:28:18,835: ERROR Exception serializing message!
Traceback (most recent call last):
File "/xds_interop_server.runfiles/com_github_grpc_grpc/src/python/grpcio/grpc/_common.py", line 87, in _transform
return transformer(message)
^^^^^^^^^^^^^^^^^^^^
File "/xds_interop_server.runfiles/com_google_protobuf/python/google/protobuf/internal/python_message.py", line 1140, in SerializeToString
if not self.IsInitialized():
^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'IsInitialized'
```

Client:

```
$ grpcurl --plaintext 127.0.0.1:8080 grpc.channelz.v1.Channelz.GetServers | grep socket_id
"socket_id": "4",
"socket_id": "5",

# requesting non-existing socket

$ grpcurl -d '{"socket_id": 10}' --plaintext 127.0.0.1:8080 grpc.channelz.v1.Channelz.GetSocket
ERROR:
Code: NotFound
Message: Failed to get the socket, please ensure your socket_id==10 is valid
```

### What did you expect to see?

The server should not log serialization error.

### What did you see instead?

```pytb
2026-05-08 19:28:18,835: ERROR Exception serializing message!
Traceback (most recent call last):
File "/xds_interop_server.runfiles/com_github_grpc_grpc/src/python/grpcio/grpc/_common.py", line 87, in _transform
return transformer(message)
^^^^^^^^^^^^^^^^^^^^
File "/xds_interop_server.runfiles/com_google_protobuf/python/google/protobuf/internal/python_message.py", line 1140, in SerializeToString
if not self.IsInitialized():
^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'IsInitialized'
```

### Anything else we should know about your project / environment?

I used xds test server as an example, but I'm pretty sure normal channelz is affected too.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.