Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safer wrapping for FFI clients. #2906

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

nihohit
Copy link
Contributor

@nihohit nihohit commented Dec 31, 2024

Use Arc instead of Box to wrap the ClientAdapter, so that the lifetime of the adapter will be extended even in cases where the client is closed during commands. This also saves on using as usize conversions to the pointer, which cause provenance to be lost and might lead to undefined behavior.
The memory cost of this change is increasing the allocation of the client by one pointer size, and the runtime cost is 4 atomic increments/decrements per command.

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one issue.
  • Commit message has a detailed description of what changed and why.
  • Tests are added or updated.
  • CHANGELOG.md and documentation files are updated.
  • Destination branch is correct - main or release
  • Create merge commit if merging release branch into main, squash otherwise.

@nihohit nihohit requested a review from a team as a code owner December 31, 2024 17:52
@nihohit nihohit force-pushed the pointers branch 2 times, most recently from 2a0e1fa to f0dd565 Compare December 31, 2024 18:08
Use `Arc` instead of `Box` to wrap the `ClientAdapter`, so that the lifetime of the adapter will be extended even in cases where the client is closed during commands.
This also saves on using `as usize` conversions to the pointer, which cause provenance to be lost and might lead to undefined behavior.

Signed-off-by: Shachar Langbeheim <[email protected]>
csharp/lib/src/lib.rs Show resolved Hide resolved
csharp/lib/src/lib.rs Show resolved Hide resolved
csharp/lib/src/lib.rs Outdated Show resolved Hide resolved
go/src/lib.rs Outdated
@@ -512,7 +515,8 @@ fn valkey_value_to_command_response(value: Value) -> RedisResult<CommandResponse
///
/// # Safety
///
/// * TODO: finish safety section.
/// This function should only be called, and should complete and call one of the response callbacks before `close_client` is called.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. I don't know what "should only be called" means. Is there something else that can be done with the function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, the doc was missing "once".

Co-authored-by: jonathanl-bq <[email protected]>
Signed-off-by: Shachar Langbeheim <[email protected]>
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.

3 participants