Skip to content

http: allowing 100 then 500 - #12185

Merged
alyssawilk merged 3 commits into
envoyproxy:masterfrom
alyssawilk:100
Jul 21, 2020
Merged

alyssawilk merged 3 commits into
envoyproxy:masterfrom
alyssawilk:100

Conversation

@alyssawilk

Copy link
Copy Markdown
Contributor

Fixing a bug where the router filter wouldn't send a local response had already been sent.

This could have been fixed in a lower-risk fashion by keeping the existing logic, and doing sendLocalReply only iff non-informational headers had not been sent. This design has the added benefit of being usable in a follow-up PR to call sendLocalResponse from encoder filters which currently force-reset the stream on the response path

Risk Level: Medium/High
Testing: updated unit tests, new integration tests
Docs Changes: n/a
Release Notes: inline
Runtime guard: envoy.reloadable_features.allow_500_after_100
Fixes #12131

Signed-off-by: Alyssa Wilk <[email protected]>
@alyssawilk

Copy link
Copy Markdown
Contributor Author

The one thing I don't like about this PR is the change to sendLocalResponse.
I'd started this as a PR which added a trySendLocalResponse to the encoder filter interface, but the router filter isn't an encoder filter so couldn't use that. I thought about having sendLocalResponse and trySendLocalResponse explicitly but then every filter arguably ought to pay attention to which was which, so I went with just amending sendLocalResponse.

Signed-off-by: Alyssa Wilk <[email protected]>

@mattklein123 mattklein123 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.

Thanks for the fix. LGTM at a high level with some small comments. Thank you!

/wait

Comment thread include/envoy/http/filter.h Outdated
Comment on lines +334 to +335
* If a response has already started (which should only happen if this is called by the router
* filter) this will either ship the reply directly to the downstream codec, or reset the stream.

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.

Technically I don't think this needs to be true, right? I think an intermediate filter could also attempt to send a local reply in error cases when the response was already started?

Comment thread source/common/http/conn_manager_impl.h Outdated
Network::Socket::OptionsSharedPtr upstream_options_;
std::unique_ptr<RouteConfigUpdateRequester> route_config_update_requester_;
std::unique_ptr<Tracing::CustomTagMap> tracing_custom_tags_{nullptr};
bool response_headers_encoded_{};

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.

nit: move this into State

Comment on lines +1543 to +1561
state_.destroyed_,
Utility::EncodeFunctions{
[&](ResponseHeaderMap& response_headers, Code& code, std::string& body,
absl::string_view& content_type) -> void {
connection_manager_.config_.localReply().rewrite(
request_headers_.get(), response_headers, stream_info_, code, body, content_type);
},
[&](ResponseHeaderMapPtr&& response_headers, bool end_stream) -> void {
if (modify_headers != nullptr) {
modify_headers(*response_headers);
}
response_headers_ = std::move(response_headers);
encodeHeadersInternal(*response_headers_, end_stream);
},
[&](Buffer::Instance& data, bool end_stream) -> void {
encodeDataInternal(data, end_stream);
}},
Utility::LocalReplyData{Grpc::Common::hasGrpcContentType(*request_headers_), code, body,
grpc_status, state_.is_head_request_});

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.

This is mostly copied from below and is somewhat nuanced and took me a couple of reads to see the difference. Is there any way to share this with just a bool that switches between internal vs. not? Up to you.

Comment thread source/common/http/conn_manager_impl.cc Outdated
}
}

// stream_info_.response_code_ is used by trySendLocalResponse to determine if non-informational

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.

Out of date comment? Also, for the next reader, can you add a bit more of a comment on where informational headers are sent? I assume that is in encode100Continue or something like that? It's not completely clear from a quick read why they wouldn't come through here. Along these lines, maybe rename to non_informational_response_headers_encoded_?

Signed-off-by: Alyssa Wilk <[email protected]>

@mattklein123 mattklein123 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!

@alyssawilk
alyssawilk merged commit d5ae400 into envoyproxy:master Jul 21, 2020

stream_info_.setResponseCodeDetails(details);
if (response_headers_.get() == nullptr) {
// If the response has not started at all, send the response through the filter chain.

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.

something for my own knowledge, if you send the response through the filter chain, do you have to explicitly call allowIteration() in case it was stopped?

KBaichoo pushed a commit to KBaichoo/envoy that referenced this pull request Jul 30, 2020
Fixing a bug where the router filter wouldn't send a local response had already been sent.

This could have been fixed in a lower-risk fashion by keeping the existing logic, and doing sendLocalReply only iff non-informational headers had not been sent. This design has the added benefit of being usable in a follow-up PR to call sendLocalResponse from encoder filters which currently force-reset the stream on the response path

Risk Level: Medium/High
Testing: updated unit tests, new integration tests
Docs Changes: n/a
Release Notes: inline
Runtime guard: envoy.reloadable_features.allow_500_after_100
Fixes envoyproxy#12131

Signed-off-by: Alyssa Wilk <[email protected]>
Signed-off-by: Kevin Baichoo <[email protected]>
scheler pushed a commit to scheler/envoy that referenced this pull request Aug 4, 2020
Fixing a bug where the router filter wouldn't send a local response had already been sent.

This could have been fixed in a lower-risk fashion by keeping the existing logic, and doing sendLocalReply only iff non-informational headers had not been sent. This design has the added benefit of being usable in a follow-up PR to call sendLocalResponse from encoder filters which currently force-reset the stream on the response path

Risk Level: Medium/High
Testing: updated unit tests, new integration tests
Docs Changes: n/a
Release Notes: inline
Runtime guard: envoy.reloadable_features.allow_500_after_100
Fixes envoyproxy#12131

Signed-off-by: Alyssa Wilk <[email protected]>
Signed-off-by: scheler <[email protected]>
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.

Envoy doesn't forward/recognize timeout response codes when proxying 100-continue

3 participants