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

[C++][Acero] Fix BackpressureConcurrentQueue::Pop() when empty #45421

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

Conversation

gitmodimo
Copy link

Rationale for this change

BackpressureConcurrentQueue::Pop() does not check for empty. This can lead to UB.

Are there any user-facing changes?

No

@gitmodimo gitmodimo requested a review from westonpace as a code owner February 4, 2025 13:57
Copy link

github-actions bot commented Feb 4, 2025

Thanks for opening a pull request!

If this is not a minor PR. Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose

Opening GitHub issues ahead of time contributes to the Openness of the Apache Arrow project.

Then could you also rename the pull request title in the following format?

GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}

or

MINOR: [${COMPONENT}] ${SUMMARY}

See also:

@@ -35,8 +35,7 @@ class ConcurrentQueue {
//
T Pop() {
std::unique_lock<std::mutex> lock(mutex_);
cond_.wait(lock, [&] { return !queue_.empty(); });
return PopUnlocked();
return PopUnlocked(lock);
Copy link
Member

Choose a reason for hiding this comment

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

The comment for Pop says it must be called on a non-empty queue?

Copy link
Author

Choose a reason for hiding this comment

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

Hmm. Didn't See that one. But still i think it is just wrong comment. Original ConcurrentQueue::Pop does check for emptiness despite the comment. Original BackpressureConcurrentQueue:Popdoes not check for emptiness and there is no comment.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm. Do you have really meet some problem here?

Copy link
Author

Choose a reason for hiding this comment

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

I encountered a problem when I reused BackpressureConcurrentQueue in new acero node (will PR soon) and pop on empty obviously caused segfaut. That was when I switched from ConcurrentQueue to BackpressureConcurrentQueue - was not expecting that. I think to the very least to comment should be moved form ConcurrentQueue::Pop (misleading) to BackpressureConcurrentQueue:Pop (missing), although I think unifying safe version of Pop makes much more sense. More verbose method like PopUnsafe can be added also if any regression occurs. LMK the way forward and I will update PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants