-
Notifications
You must be signed in to change notification settings - Fork 5
WIP: a usable CQ completion channel #83
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @dragonJACson, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request lays the groundwork for a usable completion channel by integrating the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces functionality to get completion queue events from a completion channel. This is achieved by storing a weak reference to the completion queue in its context field, which can be retrieved later. While the overall approach is sound, there are several critical issues that need to be addressed. Specifically, there are memory leaks due to improper handling of Box::into_raw, and a regression that breaks the existing setup_cq_context functionality. There is also a potential panic in get_cq_event that should be handled as an error. I've left detailed comments on these points.
| let weak_cq = Arc::downgrade(&cq_wrapper.clone()); | ||
| let boxed = Box::new(WeakGenericCompletionQueue::Extended(weak_cq)); | ||
| let raw_box = Box::into_raw(boxed); | ||
|
|
||
| unsafe { | ||
| (*cq_ex).cq_context = raw_box as *mut std::ffi::c_void; | ||
| } |
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.
This block of code introduces some issues:
-
Memory Leak (Critical):
Box::into_rawis used to store a pointer toWeakGenericCompletionQueueincq_context. This transfers ownership, but theDropimplementation forExtendedCompletionQueue(lines 417-423) doesn't deallocate this memory, causing a leak. -
API Regression (High): This change overwrites any user-provided context set via
setup_cq_context, breaking that functionality. -
Redundant Clone (Medium): The call to
cq_wrapper.clone()on line 530 is not necessary.Arc::downgradetakes a reference, soArc::downgrade(&cq_wrapper)is sufficient.
A potential solution for the first two points is to create a new struct that holds both the user's context and the WeakGenericCompletionQueue, and then store a pointer to an instance of this struct in cq_context. You would then need to manage its allocation and deallocation carefully.
| let weak_cq = Arc::downgrade(&cq_wrapper.clone()); | ||
| let boxed = Box::new(WeakGenericCompletionQueue::Basic(weak_cq)); | ||
| let raw_box = Box::into_raw(boxed); | ||
|
|
||
| unsafe { | ||
| (*cq).cq_context = raw_box as *mut std::ffi::c_void; | ||
| } |
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.
This block of code has issues similar to build_ex:
-
Memory Leak (Critical):
Box::into_rawis used to store a pointer toWeakGenericCompletionQueueincq_context. This transfers ownership, but theDropimplementation forBasicCompletionQueue(lines 335-340) doesn't deallocate this memory, causing a leak. -
API Regression (High): This change overwrites any user-provided context set via
setup_cq_context, breaking that functionality. -
Redundant Clone (Medium): The call to
cq_wrapper.clone()on line 567 is not necessary.Arc::downgradetakes a reference, soArc::downgrade(&cq_wrapper)is sufficient.
A potential solution for the first two points is to create a new struct that holds both the user's context and the WeakGenericCompletionQueue, and then store a pointer to an instance of this struct in cq_context. You would then need to manage its allocation and deallocation carefully.
|
|
||
| let weak_cq = unsafe { (*cq_wrapper.as_ptr()).upgrade() }; | ||
|
|
||
| Ok(weak_cq.unwrap()) |
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.
The use of .unwrap() here will cause a panic if weak_cq.upgrade() returns None. This can happen if the CompletionQueue is dropped before get_cq_event is called. This should be handled by returning an error, which is consistent with the function's Result return type.
| Ok(weak_cq.unwrap()) | |
| weak_cq.ok_or_else(|| GetCompletionEventErrorKind::Ibverbs(io::Error::new(io::ErrorKind::NotFound, "completion queue has been dropped")).into()) |
Codecov Report❌ Patch coverage is
🚀 New features to boost your workflow:
|
Signed-off-by: Luke Yue <lukedyue@gmail.com>
4d939d2 to
967871f
Compare
Signed-off-by: Luke Yue <lukedyue@gmail.com>
#65