ray icon indicating copy to clipboard operation
ray copied to clipboard

[Core] Cross-node channel transfer stalls when payload size is an exact multiple of kMaxGrpcPayloadSize in PushMutableObject

Open Pengkun-ZHU opened this issue 1 month ago • 1 comments

What happened + What you expected to happen

In RayletClient::PushMutableObject, the size of the last chunk is computed using modulo arithmetic:

uint64_t kMaxGrpcPayloadSize = RayConfig::instance().max_grpc_message_size() * 0.98;
uint64_t total_num_chunks = data_size / kMaxGrpcPayloadSize;
if (data_size % kMaxGrpcPayloadSize) {
  total_num_chunks++;
}

for (uint64_t i = 0; i < total_num_chunks; i++) {
  ...
  uint64_t chunk_size = (i < total_num_chunks - 1) ? kMaxGrpcPayloadSize
                                                   : (data_size % kMaxGrpcPayloadSize);

When data_size > 0 and data_size is an exact multiple of kMaxGrpcPayloadSize (for example 2 * kMaxGrpcPayloadSize), data_size % kMaxGrpcPayloadSize evaluates to 0. As a result, the final chunk RPC is sent with chunk_size = 0 instead of kMaxGrpcPayloadSize, omitting an entire chunk of payload data while still notifying receiver that total_data_size = data_size.

On the receiving node, MutableObjectProvider::HandlePushMutableObject accumulates written_so_far_[writer_object_id] += chunk_size and only calls WriteRelease() and sets reply->set_done(true) when total_written == total_data_size.

Because the last chunk's bytes are never sent: The receiver never calls WriteRelease(), so the reader blocks indefinitely (or fails with RayChannelTimeoutError). The receiver never sets reply->set_done(true), so the sender's PushMutableObject completion callback is never invoked and the writer channel polling loop stalls.

Versions / Dependencies

Ray version: master (3.0.0.dev0) OS: Ubuntu 24.04, Linux 6.18.54, x86-64 Python: 3.14.4 Bazel: 7.5.0 GCC: 15.2.0

Reproduction script

import os

GRPC_MAX_SIZE = 5 * 1024 * 1024
os.environ["RAY_max_grpc_message_size"] = str(GRPC_MAX_SIZE)

import ray
from ray.cluster_utils import Cluster
from ray.dag import InputNode


@ray.remote
class EchoActor:
    def echo(self, x):
        return x


cluster = Cluster()
node1 = cluster.add_node(num_cpus=1)
node2 = cluster.add_node(num_cpus=1)
ray.init(address=cluster.address)

driver_node = ray.get_runtime_context().get_node_id()
remote_node = node2.node_id if node1.node_id == driver_node else node1.node_id

actor = EchoActor.options(
    label_selector={ray._raylet.RAY_NODE_ID_KEY: remote_node}
).remote()

with InputNode() as inp:
    dag = actor.echo.bind(inp)

compiled_dag = dag.experimental_compile()

# Exact 1x multiple of kMaxGrpcPayloadSize 
exact_chunk_size = int(GRPC_MAX_SIZE * 0.98)
payload = b"x" * exact_chunk_size

ref = compiled_dag.execute(payload)

# Fails with RayChannelTimeoutError
assert ray.get(ref, timeout=5) == payload

Issue Severity

None

Pengkun-ZHU avatar Oct 27 '26 13:10 Pengkun-ZHU

Hi fellows @MortalHappiness @Yicheng-Lu-llll, could you weigh in and take a look into the issue and corresponding fix? the nature of this issue is quite intuitive.

Pengkun-ZHU avatar Nov 30 '26 14:11 Pengkun-ZHU