Fix seg fault when exceptions raise in folly worker#3004
Fix seg fault when exceptions raise in folly worker#3004
Conversation
| auto descriptor = std::make_shared<StreamDescriptor>(frame_and_desc.frame_.descriptor()); | ||
| pipeline_context->begin()->set_descriptor(std::move(descriptor)); | ||
| reduce_and_fix_columns(pipeline_context, frame_and_desc.frame_, ReadOptions{}, handler_data).get(); | ||
| std::shared_ptr<std::any> handler_data_ptr(std::shared_ptr<std::any>{}, &handler_data); |
There was a problem hiding this comment.
This creates a shared_ptr with a null owning pointer and a raw pointer to handler_data — a null-deleter alias — to adapt a reference into the new shared_ptr<std::any> API. Because .get() is called immediately on the next line, the caller's frame is alive for the full duration and this is safe here.
The identical pattern is used in local_versioned_engine.cpp for batch_read_and_join_internal (also guarded by .get()). Both are fragile: removing .get() or copying the pattern without the blocking call would produce a dangling pointer.
Consider propagating std::shared_ptr<std::any> all the way through batch_read_and_join_internal and read_result_from_single_frame as well (matching the rest of the chain changed in this PR), which would eliminate the aliasing wrapper entirely and remove the implicit lifetime constraint.
|
test comment update |
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
ArcticDB Code Review SummaryPR: Fix seg fault when exceptions raise in folly worker SummaryThis PR fixes a use-after-free segfault caused by Two call sites ( std::shared_ptr<std::any> handler_data_ptr(std::shared_ptr<std::any>{}, &handler_data);This is safe because both functions block synchronously (the future chain terminates with The latest commits (delta) contain only line-wrapping/formatting changes — no logic changes. API & Compatibility
Memory & Safety
Correctness
Code Quality
Testing
Build & Dependencies
Security
PR Title & Description
|
Reference Issues/PRs
https://man312219.monday.com/boards/7852509418/pulses/11573559183
What does this implement or fix?
folly::collect fails fast when a task raises an exception. If the caller's stack unwinds while other folly tasks are still running, they may access destroyed stack variables, causing a segfault.
In this issue,
handler_datahas been destroyed along with the stack, cauing seg fault.Any other comments?
Similar fix #2458
Checklist
Checklist for code changes...