-
Notifications
You must be signed in to change notification settings - Fork 44
Fix UAF in scan preloading and add OOM protection #167
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
Refactor AsyncLoadHolder to use RAII for AsyncThreadCtx tracking. This ensures tracking increments happen on the producer thread before task offloading, preventing destruction of context while tasks are still in queue.
|
Hello @yangzhengguo @zachary-blanco @fzhedu, I have submitted this PR to fix the Use-After-Free issue #147. Looking forward to your review! |
|
@Ashutosh0x Thx for the 1st contribution to Bolt! I just trigger the CI workflow and the format check is complaining. @fzhedu pls review & validate the fix when you get a time |
|
Hello @frankobe, I have fixed the formatting issues and corrected a typo in the AsyncLoadHolder constructor. I also refactored the AsyncThreadCtx tracking to use a more robust RAII-based Guard class to ensure consistent resource tracking even if task offloading fails. The format-check is now passing, and other tests are in progress. Looking forward to your review! |
| int32_t prefetchMemoryPercent_{30}; | ||
| connector::AsyncThreadCtx* asyncThreadCtx; | ||
| uint64_t preloadBytesLimit_{0}; | ||
| connector::AsyncThreadCtx::Guard inGuard; |
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.
| connector::AsyncThreadCtx::Guard inGuard; | |
| connector::AsyncThreadCtx::Guard inGuard_; |
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.
Trailing underscore is common for member variables. It's to add an underscore for better consistency.
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.
Thanks! Fixed the naming convention (added trailing underscore) and also fixed a potential memory tracking leak I noticed in the same class.
|
Thanks for the review @yangzhg! I have replaced |
|
The UT was failed
|
- Rename inGuard to inGuard_ for consistency - Fix deadlock in tableScanTest.preloadingSplitClose by unblocking executor - Fix memory tracking leak in AsyncLoadHolder
|
I've investigated the failure in TableScanTest.preloadingSplitClose. It was a deadlock caused by TableScan::close() waiting for background preloads while the executor threads were blocked by the test itself. I've updated the test to safely unblock the executor in a background thread, ensuring it can finish successfully even with the new safety checks in place. The naming conventions for member variables have also been updated, and I fixed a minor memory tracking leak in AsyncLoadHolder. |
This PR fixes a critical Use-After-Free race condition in
DirectBufferedInputandTableScanwhereAsyncThreadCtxtracking was initiated too late.Problem
The
AsyncThreadCtxcounter was being incremented (in()) inside the background task after offloading to the executor. This allowed the main thread to complete its work and return fromTableScan::close()(seeing a count of 0), leading to the destruction of the context while tasks were still in the queue.Solution
AsyncLoadHolderinDirectBufferedInput.hto use RAII forAsyncThreadCtxtracking.in()is called on the producer thread before task offloading.in()/out()) to theTableScansplit preloader.DirectBufferedInput.cpp.cc @yangzhengguo @zachary-blanco @fzhedu