-
Notifications
You must be signed in to change notification settings - Fork 65
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
base: main
Are you sure you want to change the base?
Conversation
2a0e1fa
to
f0dd565
Compare
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]>
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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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]>
Use
Arc
instead ofBox
to wrap theClientAdapter
, so that the lifetime of the adapter will be extended even in cases where the client is closed during commands. This also saves on usingas 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: