Skip to content

[Fix][Runtime][RPC] Fix remote tensor handle cleanup for RPC return values#19410

Merged
mshr-h merged 1 commit into
apache:mainfrom
tlopex:fixpc
Apr 16, 2026
Merged

[Fix][Runtime][RPC] Fix remote tensor handle cleanup for RPC return values#19410
mshr-h merged 1 commit into
apache:mainfrom
tlopex:fixpc

Conversation

@tlopex

@tlopex tlopex commented Apr 16, 2026

Copy link
Copy Markdown
Member

This PR fixes RPC tensor cleanup for tensors returned from remote calls.

When a remote function returns a Tensor, the RPC protocol sends both:

  • the remote backing data pointer
  • the remote tensor object handle used for deletion

Previously, TensorFromRemoteOpaqueHandle stored only the data pointer and called
FreeHandle(space_.data) during local tensor destruction. That is incorrect:
FreeHandle is meant for remote object handles, not raw data-space pointers.

This could lead to invalid cleanup behavior and crashes during teardown in RPC workflows, including the cross-compilation + RPC tutorial scenario reported in #18923.

This change:

  • stores the remote tensor object handle in RemoteSpace
  • calls FreeHandle(remote_tensor_handle) during tensor destruction
  • keeps cleanup fault-tolerant if the remote connection is already closed

@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 enhances RPC tensor handling by introducing an object_handle to the RemoteSpace structure, ensuring that remote tensor handles are properly released during data deallocation. It also adds fault tolerance to remote session closures within the FreeData method and includes comprehensive C++ and Python tests to verify these changes. Feedback was provided regarding an unused exception variable in a catch block to avoid potential compiler warnings.

if (space_.object_handle != nullptr) {
try {
space_.sess->FreeHandle(space_.object_handle);
} catch (const Error& e) {

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 exception variable e is unused in this catch block. To avoid potential compiler warnings, especially in builds with strict warning settings (like -Werror), it is better to omit the variable name when it is not needed.

        } catch (const Error&) {

@mshr-h mshr-h merged commit 5c17111 into apache:main Apr 16, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants