Skip to content

Conversation

@BiteTheDDDDt
Copy link
Contributor

@BiteTheDDDDt BiteTheDDDDt commented Oct 23, 2025

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] [2]

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

    • 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
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

@Thearas
Copy link
Contributor

Thearas commented Oct 23, 2025

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@BiteTheDDDDt
Copy link
Contributor Author

run buildall

@BiteTheDDDDt
Copy link
Contributor Author

run buildall

@hello-stephen
Copy link
Contributor

BE UT Coverage Report

Increment line coverage 88.89% (16/18) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 52.62% (17939/34089)
Line Coverage 37.86% (162781/429963)
Region Coverage 32.28% (124158/384595)
Branch Coverage 33.68% (54375/161445)

@hello-stephen
Copy link
Contributor

BE Regression && UT Coverage Report

Increment line coverage 50.00% (9/18) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 71.31% (23867/33471)
Line Coverage 57.73% (248429/430312)
Region Coverage 52.88% (206156/389861)
Branch Coverage 54.62% (88724/162436)

throw;
} catch (const std::exception& e) {
LOG(WARNING) << "Exception swallowed in Defer destructor during unwind: "
<< e.what();
Copy link
Contributor

Choose a reason for hiding this comment

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

In this case, should print stack here, we should know where the exception happens.

@BiteTheDDDDt
Copy link
Contributor Author

run buildall

1 similar comment
@BiteTheDDDDt
Copy link
Contributor Author

run buildall

Copy link
Contributor

@HappenLee HappenLee left a comment

Choose a reason for hiding this comment

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

LGTM

@github-actions github-actions bot added the approved Indicates a PR has been approved by one committer. label Oct 26, 2025
@github-actions
Copy link
Contributor

PR approved by at least one committer and no changes requested.

@github-actions
Copy link
Contributor

PR approved by anyone and no changes requested.

@BiteTheDDDDt
Copy link
Contributor Author

run buildall

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by one committer. dev/4.0.x reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants