Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rpc server exception handling #2917

Merged

Conversation

mmaslankaprv
Copy link
Member

Cover letter

Our RPC implementation support propagating server errors to the client.
For this we use a meta field in RPC response header. The status that
is included into header::meta field indicates whether the request is
successful or its execution failed on the server side. When status
indicates an error response body is empty.

Fixed an error caused by the fact that we tried to parse response body
before we checked the status flag. This caused parsing error and broken
promise exception on the client side.

@@ -33,6 +33,9 @@ struct server_context_impl final : streaming_context {
~server_context_impl() override { res.probe().request_completed(); }
const header& get_header() const final { return hdr; }
void signal_body_parse() final { pr.set_value(); }
void body_parse_exception(const std::exception_ptr& e) final {
pr.set_exception(e);
Copy link
Contributor

Choose a reason for hiding this comment

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

Exception ptr can be copied. Don’t you want to move the exception?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Member

Choose a reason for hiding this comment

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

what is the point of std::move(e) here? exception_ptr is trivially copyable

Copy link
Member Author

Choose a reason for hiding this comment

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

exception_ptr has semantics similar to shared_ptr, there is no need to copy it.

emaxerrno
emaxerrno previously approved these changes Nov 9, 2021
Copy link
Contributor

@emaxerrno emaxerrno left a comment

Choose a reason for hiding this comment

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

Great find.

src/v/rpc/types.h Show resolved Hide resolved
Data are always set together with header. We may leverage that fact and
create appropriate constructor.

Signed-off-by: Michal Maslanka <michal@vectorized.io>
Our RPC implementation support propagating server errors to the client.
For this we use a `meta` field in RPC response header. The status that
is included into `header::meta` field indicates whether the request is
successful or its execution failed on the server side. When status
indicates an error response body is empty.

Fixed an error caused by the fact that we tried to parse response body
before we checked the status flag. This caused parsing error and broken
promise exception on the client side.

Signed-off-by: Michal Maslanka <michal@vectorized.io>
Added field to response of a service that is supposed to thrown an
exception during execution. This way we trigger situation in which
response that contains error in header has different payload size than
successful response.

Signed-off-by: Michal Maslanka <michal@vectorized.io>
src/v/rpc/transport.h Show resolved Hide resolved
src/v/rpc/transport.h Show resolved Hide resolved
@mmaslankaprv mmaslankaprv force-pushed the fix-rpc-server-exception-handling branch from 58507ca to 82a9c2f Compare November 9, 2021 19:32
@dswang dswang added this to the v21.10.1 milestone Nov 10, 2021
@mmaslankaprv mmaslankaprv force-pushed the fix-rpc-server-exception-handling branch from 82a9c2f to fc51875 Compare November 10, 2021 06:51
Streaming context promise must be set with exception when rpc body
parsing failed. This way we will forward exception to rpc transport read
dispatch loop. Not setting an exception in body parsing promise would
lead to `broken_promise` exception since the promise would be deleted
before setting its value

Signed-off-by: Michal Maslanka <michal@vectorized.io>
@mmaslankaprv mmaslankaprv force-pushed the fix-rpc-server-exception-handling branch from fc51875 to 6332a91 Compare November 10, 2021 07:11
@mmaslankaprv mmaslankaprv merged commit b51e1eb into redpanda-data:dev Nov 10, 2021
dotnwat added a commit that referenced this pull request Nov 11, 2021
This pull request was closed.
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.

4 participants