[Fix][Runtime][RPC] Fix remote tensor handle cleanup for RPC return values#19410
Merged
Conversation
Contributor
There was a problem hiding this comment.
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) { |
Contributor
mshr-h
approved these changes
Apr 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes RPC tensor cleanup for tensors returned from remote calls.
When a remote function returns a
Tensor, the RPC protocol sends both:Previously,
TensorFromRemoteOpaqueHandlestored only the data pointer and calledFreeHandle(space_.data)during local tensor destruction. That is incorrect:FreeHandleis 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:
RemoteSpaceFreeHandle(remote_tensor_handle)during tensor destruction