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

refactor(app/core): prepare rescue body for http-body upgrade #3616

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cratelyn
Copy link
Collaborator

@cratelyn cratelyn commented Feb 13, 2025

refactor(app/core): prepare rescue body for http-body upgrade

this commit makes some minor alterations to our error recovery body
middleware. see linkerd/linkerd2#8733 for more
information.

this commit removes an assert! statement from the implementation of
<Response<R, B> as Body>::poll_data(). see the documentation of
Body::poll_frame():

Once the end of the stream is reached, implementations should
continue to return [Poll::Ready(None)].

hyperium/http-body@1090bff#diff-33aabe8c2aaa7614022addf244245e09bbff576a67a9ae3c6938c8a868201d36R60-R61

to do this, this commit introduces a distinct terminal state
Inner::Rescued to represent when the underlying B-typed body has
yielded an error and been rescued. once in this state the body will
yield no more data frames, instead yielding a collection of trailers
describing the mid-stream error that was encountered by the underlying
body.

the call to R::rescue is also moved down into the helper function fka
grpc_trailers(). this helps the function follow the grain of our
"state machine" a little more directly.

see #3615, #3614, and #3611 for pretext to this change.

Base automatically changed from kate/app-core.rescue-body-continues-to-yield-ready-none to main February 13, 2025 15:41
@cratelyn cratelyn force-pushed the kate/app-core.rescue-body-is-prepared-for-poll-frame branch 2 times, most recently from 424fa9a to ba9231d Compare February 14, 2025 16:58
this commit makes some minor alterations to our error recovery body
middleware. see linkerd/linkerd2#8733 for more
information.

this commit removes an `assert!` statement from the implementation of
`<Response<R, B> as Body>::poll_data()`. see the documentation of
`Body::poll_frame()`:

> Once the end of the stream is reached, implementations should
> continue to return [`Poll::Ready(None)`].

hyperium/http-body@1090bff#diff-33aabe8c2aaa7614022addf244245e09bbff576a67a9ae3c6938c8a868201d36R60-R61

to do this, this commit introduces a distinct terminal state
`Inner::Rescued` to represent when the underlying `B`-typed body has
yielded an error and been rescued. once in this state the body will
yield no more data frames, instead yielding a collection of trailers
describing the mid-stream error that was encountered by the underlying
body.

the call to `R::rescue` is also moved down into the helper function fka
`grpc_trailers()`. this helps the function follow the grain of our
"state machine" a little more directly.

see #3615, #3614, and #3611 for pretext to this change.

Signed-off-by: katelyn martin <[email protected]>
@cratelyn cratelyn force-pushed the kate/app-core.rescue-body-is-prepared-for-poll-frame branch from ba9231d to 4bcb5fe Compare February 14, 2025 16:59
@cratelyn cratelyn marked this pull request as ready for review February 14, 2025 17:03
@cratelyn cratelyn requested a review from a team as a code owner February 14, 2025 17:03
@olix0r olix0r self-assigned this Feb 14, 2025
Comment on lines -78 to +87
} => {
// should not be calling poll_data if we have set trailers derived from an error
assert!(trailers.is_none());
match inner.poll_data(cx) {
Poll::Ready(Some(Err(error))) => {
let SyntheticHttpResponse {
grpc_status,
message,
..
} = rescue.rescue(error)?;
let t = Self::grpc_trailers(grpc_status, &message, *emit_headers);
*trailers = Some(t);
Poll::Ready(None)
}
data => data,
} => match inner.poll_data(cx) {
Poll::Ready(Some(Err(error))) => {
// The inner body has yielded an error, which we will try to rescue. If so,
// store our synthetic trailers reporting the error.
let trailers = Self::rescue(error, rescue, *emit_headers)?;
self.set_rescued(trailers);
Poll::Ready(None)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is the important part to look at ☝️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants