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

   ### What problem does this PR solve?
   This pull request improves the safety and robustness of the `Defer` utility 
by enhancing its exception handling during destruction and adds unit tests to 
verify the new behavior. The main focus is to ensure that exceptions thrown by 
deferred closures are handled correctly, especially during stack unwinding, to 
prevent unexpected program termination.
   
   **Enhancements to exception handling in `Defer`:**
   
   * Updated the destructor of the `Defer` class in `defer_op.h` to distinguish 
between normal destruction and stack unwinding:
     * If an exception is already active (stack unwinding), any exception 
thrown by the deferred closure is caught and swallowed, with a warning logged 
instead of calling `std::terminate`.
     * If no exception is active, exceptions from the closure are allowed to 
propagate. The destructor is now marked `noexcept(false)` to permit this. 
[[1]](diffhunk://#diff-84aeaa7dcc3d0aefe32d3830f93e34bad19d54bff6cacbab39e39749c4c45133R21-R23)
 
[[2]](diffhunk://#diff-84aeaa7dcc3d0aefe32d3830f93e34bad19d54bff6cacbab39e39749c4c45133R35-R72)
   
   **Testing improvements:**
   
   * Added a new test file `defer_op_test.cpp` with unit tests to verify:
     * That exceptions from the deferred closure propagate when not unwinding.
     * That exceptions are swallowed (and do not cause termination) when the 
destructor runs during stack unwinding.
   
   ### Check List (For Author)
   
   - Test <!-- At least one of them must be included. -->
       - [ ] Regression test
       - [ ] Unit Test
       - [ ] Manual test (add detailed scripts or steps below)
       - [ ] No need to test or manual test. Explain why:
           - [ ] This is a refactor/code format and no logic has been changed.
           - [ ] Previous test can cover this change.
           - [ ] No code files have been changed.
           - [ ] Other reason <!-- Add your reason?  -->
   
   - Behavior changed:
       - [ ] No.
       - [ ] Yes. <!-- Explain the behavior change -->
   
   - Does this need documentation?
       - [ ] No.
       - [ ] Yes. <!-- Add document PR link here. eg: 
https://github.com/apache/doris-website/pull/1214 -->
   
   ### Check List (For Reviewer who merge this PR)
   
   - [ ] Confirm the release note
   - [ ] Confirm test cases
   - [ ] Confirm document
   - [ ] Add branch pick label <!-- Add branch pick label that this PR should 
merge into -->
   
   


-- 
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