Skip to content

buffer filter: add content-length when ending stream with trailers - #8609

Merged
junr03 merged 3 commits into
envoyproxy:masterfrom
junr03:buffer-filter
Oct 22, 2019
Merged

junr03 merged 3 commits into
envoyproxy:masterfrom
junr03:buffer-filter

Conversation

@junr03

@junr03 junr03 commented Oct 14, 2019

Copy link
Copy Markdown
Member

Description: #7848 introduced content-length population in the buffer filter. However, it is only populated if the client stream ends on a data frame. This PR adds content-length population when closing the stream via trailers.
Risk Level: low - expanded functionality runtime guarded.
Testing: unit and integration tests.
Release Notes: I believe the current release notes added by #7848 are still adequate.

@junr03
junr03 requested a review from euroelessar October 14, 2019 19:51
Comment on lines +98 to +106
// request_headers_ is initialized iff plugin is enabled.
if (request_headers_ != nullptr && request_headers_->ContentLength() == nullptr) {
ASSERT(!settings_->disabled());
if (Runtime::runtimeFeatureEnabled(
"envoy.reloadable_features.buffer_filter_populate_content_length")) {
request_headers_->insertContentLength().value(content_length_);
}
}

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.

Can this code be moved to a shared function, please?
It's non-trivial enough to care about the code duplication.

Comment on lines +77 to +78
codec_client_->sendData(*request_encoder_, "789", false);
codec_client_->sendTrailers(*request_encoder_, Http::TestHeaderMapImpl{});

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.

Trying to improve my knowledge of internal envoy logic: is this semantically different from sendData(..., true)?
How are either of them materialized on the wire?

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.

yep it is different. sendTrailers will encode a HEADERS frame with END_STREAM true while sendData(data, true) encodes a DATA frame with END_STREAM true. Envoy mobile closes client streams with trailers, so the content-length headers was not getting set in our edge infrastructure.

@alyssawilk alyssawilk left a comment

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.

LGTM modulo shared utility function

Jose Nino
fmt
Signed-off-by: Jose Nino <[email protected]>
euroelessar
euroelessar previously approved these changes Oct 15, 2019

@euroelessar euroelessar left a comment

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.

Looks good to me

alyssawilk
alyssawilk previously approved these changes Oct 15, 2019

@alyssawilk alyssawilk left a comment

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.

LGTM - feel free to self merge once CI is working

@junr03

junr03 commented Oct 17, 2019

Copy link
Copy Markdown
Member Author

looking at test failures

Signed-off-by: Jose Nino <[email protected]>
@junr03
junr03 dismissed stale reviews from alyssawilk and euroelessar via 98e03ce October 17, 2019 22:17
codec_client_->sendData(*request_encoder_, "456", false);
codec_client_->sendData(*request_encoder_, "789", false);
Http::TestHeaderMapImpl request_trailers{{"request", "trailer"}};
codec_client_->sendTrailers(*request_encoder_, request_trailers);

@junr03 junr03 Oct 17, 2019 •

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.

@alyssawilk with an empty map I got an asan failure because of taking a reference from a nullptr here:

nghttp2_submit_trailer(parent_.session_, stream_id_, &final_headers[0], final_headers.size());

Things obviously end up fine because nghttp2 first checks the array length. Do you think it is worth doing something envoy side so that we can send empty trailers without tripping the address sanitizer?

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.

I'm also confused how content length changes here result in empty trailers. Can you clue me in a bit more?

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.

oh sorry, I meant that when I originally wrote the test by sending an empty trailers map (78f6b39#diff-13f71f37c14f0986b566cbf97601bf44R78) I was getting an ASAN failure. So not an effect of the patch, but rather of how I wrote the test.

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.

Oh gotcha! Yeah, if sending an empty trailers map causes ASAN bugs, we should file and fix that as a separate PR lest some filters clear the only trailers entry and cause problems
@mattklein123 for visibility.

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.

reference issue: #8720.

@alyssawilk alyssawilk left a comment

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.

LGTM modulo filing a tracking issue regarding the trailers bug

@junr03
junr03 merged commit 50edccb into envoyproxy:master Oct 22, 2019
@junr03
junr03 deleted the buffer-filter branch October 22, 2019 16:27
spenceral added a commit to spenceral/envoy that referenced this pull request Oct 23, 2019
* master: (54 commits)
  Update dependencies - Go, Bazel toos, xxHash, nanopb, rules_go, curl, protobuf, Jinja, yaml-cpp, re2 (envoyproxy#8728)
  test: increase coverage of listener_manager_impl.cc (envoyproxy#8737)
  test: modify some macros to reduce number of uncovered lines reported (envoyproxy#8725)
  build: add a script to setup clang (envoyproxy#8682)
  http: fix ssl_redirect on external (envoyproxy#8664)
  docs: update fedora build requirements (envoyproxy#8641)
  fix draining listener removal logs (envoyproxy#8733)
  dubbo: fix router doc (envoyproxy#8734)
  server: provide server health status when stats disabled (envoyproxy#8482)
  router: adding a knob to configure a cap on buffering for shadowing/retries (envoyproxy#8574)
  tcp proxy: add default 1 hour idle timeout (envoyproxy#8705)
  thrift: fix filter names in docs (envoyproxy#8726)
  Quiche changes to avoid gcc flags on Windows (envoyproxy#8514)
  test: increase test coverage in Router::HeaderParser (envoyproxy#8721)
  admin: add drain listeners endpoint  (envoyproxy#8415)
  buffer filter: add content-length when ending stream with trailers (envoyproxy#8609)
  clarify draining option docs (envoyproxy#8712)
  build: ignore go-control-plane mirror git commit error code (envoyproxy#8703)
  api: remove API type database from checked in artifacts. (envoyproxy#8716)
  admin: correct help strings (envoyproxy#8710)
  ...

Signed-off-by: Spencer Lewis <[email protected]>
derekargueta pushed a commit to derekargueta/envoy that referenced this pull request Oct 24, 2019
…nvoyproxy#8609)

Description: envoyproxy#7848 introduced content-length population in the buffer filter. However, it is only populated if the client stream ends on a data frame. This PR adds content-length population when closing the stream via trailers.
Risk Level: low - expanded functionality runtime guarded.
Testing: unit and integration tests.
Release Notes: I believe the current release notes added by envoyproxy#7848 are still adequate.

Signed-off-by: Jose Nino <[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.

3 participants