Skip to content

[GLUTEN-12911][VL] Fix memory pool holding in async thread - #12919

Open
FelixYBW wants to merge 3 commits into
apache:mainfrom
FelixYBW:fix_12911
Open

[GLUTEN-12911][VL] Fix memory pool holding in async thread#12919
FelixYBW wants to merge 3 commits into
apache:mainfrom
FelixYBW:fix_12911

Conversation

@FelixYBW

@FelixYBW FelixYBW commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Solve issue #12911

Without the barrier, it's possible we mark the load as canceled, but it's never scheduled before the timeout, so it holds the memory pool pointer all the time.

The barrier will wait until the load is scheduled and exits.

@github-actions github-actions Bot added the VELOX label Aug 28, 2026

@philo-he philo-he left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This fix looks more robust. Could you rebase the PR and let the CI be re-triggered? Not sure if the CI failure is related. Thanks.

if (!load->loadOrFuture(&waitFuture)) {
auto& exec = folly::QueuedImmediateExecutor::instance();
std::move(waitFuture).via(&exec).wait();
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

With the barrier introduced, the above kLoading loop seems redundant. Do we need to remove it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should be, but no hurt. Let's keep it there until someone can verify.

@FelixYBW
FelixYBW marked this pull request as ready for review September 3, 2026 15:33
Copilot AI lite review requested due to automatic review settings September 3, 2026 15:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The updated header introduces direct dependencies (e.g., folly::getKeepAliveToken, std::make_unique) but doesn’t include the corresponding headers, making the build fragile due to reliance on transitive includes.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR addresses Velox backend issue #12911 by ensuring async IO load closures don’t retain MemoryPool references past GlutenDirectBufferedInput destruction, preventing pools_.size() != 0 failures during memory manager teardown.

Changes:

  • Introduces an ExecutorBarrier wrapper (owned by GlutenDirectBufferedInput) so async load enqueues can be explicitly drained at destruction time.
  • Updates the GlutenDirectBufferedInput destructor to waitAll() on the barrier (with exception swallowing/logging) after cancelling planned loads and waiting on in-flight loads.
  • Adjusts clone() to pass the raw executor so clones don’t enqueue onto the original instance’s barrier.
File summaries
File Description
cpp/velox/memory/GlutenDirectBufferedInput.h Wraps the IO executor with an ExecutorBarrier and waits for queued async-load closures to drain during destruction to avoid lingering MemoryPool references.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +20 to +23
#include <glog/logging.h>

#include "velox/dwio/common/DirectBufferedInput.h"
#include "velox/dwio/common/ExecutorBarrier.h"
// gone.
if (barrier() != nullptr) {
try {
barrier()->waitAll();

@boneanxs boneanxs Sep 10, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The task will keep waiting, will there be any issue like the task hangs there forever?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It depends on the OS when it schedules the I/O thread. If your system can't schedule the ready thread, it means your system is already hung.

Copilot AI review requested due to automatic review settings September 10, 2026 03:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

} catch (const std::exception& e) {
// waitAll() rethrows an exception raised by any of the loads. It must
// not escape the destructor: the loads were cancelled anyway.
LOG(WARNING) << "Async load failed while destructing GlutenDirectBufferedInput: " << e.what();
Comment on lines +20 to +21
#include <glog/logging.h>

}

folly::Executor* const rawExecutor_;
const std::unique_ptr<facebook::velox::dwio::common::ExecutorBarrier> barrier_;

@philo-he philo-he left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@philo-he philo-he changed the title [VL] Fix memory pool holding in async thread [GLUTEN-12911][VL] Fix memory pool holding in async thread Sep 10, 2026
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.

4 participants