yiguolei opened a new pull request, #70691:
URL: https://github.com/apache/doris/pull/70691

   ### Background
   
   Async result writer callbacks capture a weak task context and raw pointers 
to RuntimeState and the writer. Pipeline task diagnostics also access 
RuntimeState, whose lifetime is owned by the fragment.
   
   ### What problem does this PR solve?
   
   Issue Number: None
   Related PR: None
   PR Type: Bugfix
   
   Problem Summary:
   
   An async writer callback can start after cancellation releases its fragment. 
SCOPED_ATTACH_TASK previously dereferenced RuntimeState before validating the 
weak task context, so an expired callback could access freed memory. Lock the 
context before attachment, and move the instance-ID read in pipeline task 
diagnostics after its existing fragment lifetime check.
   
   ### Details
   
   - **Frequency:** Timing-dependent when an async writer remains queued during 
fragment teardown; no dynamic reproduction is claimed.
   - **Root cause:** RuntimeState was dereferenced before acquiring the context 
that protects its lifetime.
   - **Why existing tests missed it:** Async writer tests call process_block 
directly rather than exercising the queued callback attachment ordering. No 
reproducing test was identified for the diagnostic path.
   - **Fix:** Validate the captured weak task context before attaching the 
writer callback. Print the diagnostic instance ID only after obtaining a strong 
fragment reference and passing the finalized check.
   - **Other paths and branches:** The shared AsyncResultWriter entry covers 
its subclasses. No memory-reclamation or scheduler state-machine changes are 
included.
   - **Behavior change:** Expired writer callbacks return before accessing 
RuntimeState. Finalized or expired-fragment task summaries omit InstanceId; 
active summaries print it after the task summary. No protocol or storage-format 
changes.
   
   ### Testing
   
   - Repository clang-format v16 formatting/checking scripts passed on isolated 
copies of both modified files during development; the patches applied unchanged 
to the latest master.
   - git diff --cached --check passed on the PR branch.
   - Previously attempted ./run-be-ut.sh --run --filter=AsyncResultWriterTest.* 
-j 4 on macOS arm64; it stopped during Java environment validation because no 
JDK was installed. Tests did not compile or execute.
   - No unit tests added, as requested by the author. BE build, clang-tidy, and 
ASAN/TSAN reproduction remain unverified.
   
   ### Notes for Reviewers
   
   The diagnostic change removes an unguarded access, but a normal production 
UAF trigger for that particular diagnostic call has not been established. The 
async callback cancellation path is the primary fix.
   
   ### Release note
   
   Avoid a potential BE crash when an async result writer starts after its 
fragment has been cancelled and released.
   
   ### Check List (For Author)
   
   - Behavior changed: Yes (see Details)
   - Does this need documentation: No
   - Pre-submission status: Partially verified: formatting and static review 
completed; build and runtime validation remain outstanding.
   
   ### AI Disclosure
   
   - Tool: Codex
   - Generated: Code and PR description.
   - Human review: Pending.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to