Skip to content

crimson/common/errorator: disallow void-returning error handlers - #55735

Merged
cyx1231st merged 4 commits into
ceph:mainfrom
xxhdx1985126:wip-crimson-errorator-void-handler
May 16, 2024
Merged

cyx1231st merged 4 commits into
ceph:mainfrom
xxhdx1985126:wip-crimson-errorator-void-handler

Conversation

@xxhdx1985126

@xxhdx1985126 xxhdx1985126 commented Feb 25, 2024 •

Copy link
Copy Markdown
Member

Fixes: https://tracker.ceph.com/issues/64556
Signed-off-by: Xuehan Xu [email protected]

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands
  • jenkins retest this please
  • jenkins test classic perf
  • jenkins test crimson perf
  • jenkins test signed
  • jenkins test make check
  • jenkins test make check arm64
  • jenkins test submodules
  • jenkins test dashboard
  • jenkins test dashboard cephadm
  • jenkins test api
  • jenkins test docs
  • jenkins render docs
  • jenkins test ceph-volume all
  • jenkins test ceph-volume tox
  • jenkins test windows
  • jenkins test rook e2e

@xxhdx1985126
xxhdx1985126 requested a review from a team as a code owner February 25, 2024 04:29
@xxhdx1985126
xxhdx1985126 force-pushed the wip-crimson-errorator-void-handler branch from 0743bc9 to 14ac6c8 Compare February 25, 2024 04:38
@xxhdx1985126 xxhdx1985126 reopened this Feb 26, 2024
@xxhdx1985126
xxhdx1985126 force-pushed the wip-crimson-errorator-void-handler branch 2 times, most recently from bc39a66 to 54f7dc9 Compare February 26, 2024 06:01
@xxhdx1985126

Copy link
Copy Markdown
Member Author

jenkins test make check

Comment thread src/crimson/common/errorator.h Resolved
@xxhdx1985126
xxhdx1985126 force-pushed the wip-crimson-errorator-void-handler branch from 54f7dc9 to 4390e10 Compare February 27, 2024 04:59
@xxhdx1985126
xxhdx1985126 requested a review from a team as a code owner February 27, 2024 04:59
@xxhdx1985126 xxhdx1985126 changed the title crimson/common/errorator: reconstruct the result future when the error handler returns void crimson/common/errorator: disallow void-returning error handlers Feb 27, 2024
@xxhdx1985126
xxhdx1985126 requested a review from a team February 27, 2024 06:37

@cyx1231st cyx1231st left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@liu-chunmei

Copy link
Copy Markdown
Contributor

@xxhdx1985126 I don't very understand the problem, if we return void, what happened? why there is no complier error if we can't return void?

@xxhdx1985126

Copy link
Copy Markdown
Member Author

@xxhdx1985126 I don't very understand the problem, if we return void, what happened? why there is no complier error if we can't return void?

To invoke error handlers, the exception of the future has to be extracted out, which would invalidate the future. When the error handler returns void, the invalid future is returned, and later future::then() invocations would all be invalid.

@liu-chunmei

Copy link
Copy Markdown
Contributor

@xxhdx1985126 I don't very understand the problem, if we return void, what happened? why there is no complier error if we can't return void?

To invoke error handlers, the exception of the future has to be extracted out, which would invalidate the future. When the error handler returns void, the invalid future is returned, and later future::then() invocations would all be invalid.

so when return no_touch_error_marker, the ::then will not be invoked, right?

@xxhdx1985126

Copy link
Copy Markdown
Member Author

@xxhdx1985126 I don't very understand the problem, if we return void, what happened? why there is no complier error if we can't return void?

To invoke error handlers, the exception of the future has to be extracted out, which would invalidate the future. When the error handler returns void, the invalid future is returned, and later future::then() invocations would all be invalid.

so when return no_touch_error_marker, the ::then will not be invoked, right?

No, with void-returning handlers, the ::then() invocation will be invalid and crash the whole OSD. This pr prevents this case by banning void-returning handlers.

@liu-chunmei

liu-chunmei commented Feb 29, 2024 •

Copy link
Copy Markdown
Contributor

@xxhdx1985126 I don't very understand the problem, if we return void, what happened? why there is no complier error if we can't return void?

To invoke error handlers, the exception of the future has to be extracted out, which would invalidate the future. When the error handler returns void, the invalid future is returned, and later future::then() invocations would all be invalid.

so when return no_touch_error_marker, the ::then will not be invoked, right?

No, with void-returning handlers, the ::then() invocation will be invalid and crash the whole OSD. This pr prevents this case by banning void-returning handlers.

@xxhdx1985126 the exception future is extracted out and handled in error handler, if we return non void future such as seastar::now, what is the following logic? the ::then continue execute based on this future?

@xxhdx1985126

Copy link
Copy Markdown
Member Author

@xxhdx1985126 the exception future is extracted out and handled in error handler, if we return non void future such as seastar::now, what is the following logic? the ::then continue execute based on this future?

Yes, but we have to return futures with the same type as the exception-extracted-out future, if that future is not seastar::future<>, we can't return seastar::now(), which is why we can only choose to ban void-returning handlers.

@liu-chunmei

liu-chunmei commented Feb 29, 2024 •

Copy link
Copy Markdown
Contributor

for some critical error happened, system should be terminated, such as std::exit(), ceph_abort(), abort() are called in error handler, do we still need make them return a ready future? I think the future will not get chance to return, right?

@xxhdx1985126

Copy link
Copy Markdown
Member Author

for some critical error happened, system should be terminated, such as std::exit(), ceph_abort(), abort() are called in error handler, do we still need make them return a ready future?

Or use assert_all()

@liu-chunmei

liu-chunmei commented Feb 29, 2024 •

Copy link
Copy Markdown
Contributor

for some critical error happened, system should be terminated, such as std::exit(), ceph_abort(), abort() are called in error handler, do we still need make them return a ready future?

Or use assert_all()

assert_all also call ceph_abort(), I mean for that critical error, program should be terminated immediately otherwise there are logical error if continue, so call std::ext(), ceph_about() and needn't return any future, but for some tiny error, the system still can going on, or the error fixed in error handler, then we can return a ready future to make the program continue.

so which error handle cause the void return and cause system crash, why we don't use abort() there, is it a tiny error?

@xxhdx1985126

xxhdx1985126 commented Feb 29, 2024 •

Copy link
Copy Markdown
Member Author

I mean for that critical error, program should be terminated immediately otherwise there are logical error if continue, so call std::ext(), ceph_about() and needn't return any future,

For any non-void-returning functions, not only those return futures, we always have to return a valid value, even if we need to terminate the process immediately. Because the termination is an action at runtime and returning a value is a compile time requirement.

@liu-chunmei

Copy link
Copy Markdown
Contributor

I mean for that critical error, program should be terminated immediately otherwise there are logical error if continue, so call std::ext(), ceph_about() and needn't return any future,

For any non-void-returning functions, not only those return futures, we always have to return a valid value, even if we need to terminate the process immediately. Because the termination is an action at runtime and returning a value is a compile time requirement.

we didn't meet any compile error report before so seems it is not have to.

@xxhdx1985126

xxhdx1985126 commented Feb 29, 2024 •

Copy link
Copy Markdown
Member Author

I mean for that critical error, program should be terminated immediately otherwise there are logical error if continue, so call std::ext(), ceph_about() and needn't return any future,

For any non-void-returning functions, not only those return futures, we always have to return a valid value, even if we need to terminate the process immediately. Because the termination is an action at runtime and returning a value is a compile time requirement.

we didn't meet any compile error report before so seems it is not have to.

That's because we allow void-returning handlers which triggerred the runtime failure: https://tracker.ceph.com/issues/64556

@xxhdx1985126

Copy link
Copy Markdown
Member Author

@liu-chunmei @cyx1231st I've just modified this pr to switch to assert_all() when the error handler is deemed to abort the process. Please take a look, thanks:-)

@xxhdx1985126
xxhdx1985126 force-pushed the wip-crimson-errorator-void-handler branch from 061115a to 7ebe08a Compare March 7, 2024 10:51
@xxhdx1985126

Copy link
Copy Markdown
Member Author

jenkins retest this please

1 similar comment
@xxhdx1985126

Copy link
Copy Markdown
Member Author

jenkins retest this please

@cyx1231st

Copy link
Copy Markdown
Member

I suppose this PR is good, remove if there are any concerns ^

@xxhdx1985126 xxhdx1985126 mentioned this pull request Mar 13, 2024
4 of 14 tasks
Comment thread src/crimson/common/errorator.h Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Before this commit ep was an r-value reference; now technically it an instance of std::exception_ptr constructed from r-value. I haven't checked whether this brings any penalty but is the change intentional?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah, sorry, this is not intentional, will correct it.

Comment thread src/crimson/common/errorator.h Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

just a nit: per the convention in the file – Func&& f.

Comment thread src/crimson/common/errorator.h Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

std::forward. I guess the intention is to perfectly forward f.

Comment thread src/crimson/common/errorator.h Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

std::forward.

@xxhdx1985126
xxhdx1985126 force-pushed the wip-crimson-errorator-void-handler branch from 7ebe08a to fbd364b Compare March 14, 2024 06:49
@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@xxhdx1985126
xxhdx1985126 force-pushed the wip-crimson-errorator-void-handler branch from fbd364b to 0043fa9 Compare March 23, 2024 08:17
@xxhdx1985126

Copy link
Copy Markdown
Member Author

jenkins test api

@cyx1231st

Copy link
Copy Markdown
Member

@rzarzynski @athanatos does the fix look good to you?

@cyx1231st

Copy link
Copy Markdown
Member

@athanatos @Matan-B Looks the failures are unrelated to this PR, are you good with the test results?

@cyx1231st
cyx1231st merged commit d50b94f into ceph:main May 16, 2024
@xxhdx1985126
xxhdx1985126 deleted the wip-crimson-errorator-void-handler branch May 16, 2024 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants