-
Notifications
You must be signed in to change notification settings - Fork 5.5k
http conn man: fix memory leak with watermark buffer #23401
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
Merged
KBaichoo
merged 3 commits into
envoyproxy:main
from
Hexta:fix-watermarkbuffer-memory-leak-with-internal-redirect
Oct 14, 2022
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -237,6 +237,91 @@ TEST_P(Http2BufferWatermarksTest, ShouldCreateFourBuffersPerAccount) { | |
| EXPECT_TRUE(buffer_factory_->waitUntilExpectedNumberOfAccountsAndBoundBuffers(0, 0)); | ||
| } | ||
|
|
||
| TEST_P(Http2BufferWatermarksTest, AccountsAndInternalRedirect) { | ||
| Http::TestResponseHeaderMapImpl redirect_response_{ | ||
| {":status", "302"}, {"content-length", "0"}, {"location", "http://authority2/new/url"}}; | ||
|
|
||
| auto handle = config_helper_.createVirtualHost("handle.internal.redirect"); | ||
| handle.mutable_routes(0)->set_name("redirect"); | ||
| handle.mutable_routes(0)->mutable_route()->mutable_internal_redirect_policy(); | ||
| config_helper_.addVirtualHost(handle); | ||
| initialize(); | ||
|
|
||
| codec_client_ = makeHttpConnection(lookupPort("http")); | ||
|
|
||
| default_request_headers_.setHost("handle.internal.redirect"); | ||
| IntegrationStreamDecoderPtr response = | ||
| codec_client_->makeHeaderOnlyRequest(default_request_headers_); | ||
|
|
||
| waitForNextUpstreamRequest(); | ||
|
|
||
| if (streamBufferAccounting()) { | ||
| EXPECT_EQ(buffer_factory_->numAccountsCreated(), 1); | ||
| } else { | ||
| EXPECT_EQ(buffer_factory_->numAccountsCreated(), 0); | ||
| } | ||
|
|
||
| upstream_request_->encodeHeaders(redirect_response_, true); | ||
| waitForNextUpstreamRequest(); | ||
|
|
||
| upstream_request_->encodeHeaders(default_response_headers_, true); | ||
|
|
||
| ASSERT_TRUE(response->waitForEndStream()); | ||
| ASSERT_TRUE(response->complete()); | ||
|
|
||
| if (streamBufferAccounting()) { | ||
| EXPECT_EQ(buffer_factory_->numAccountsCreated(), 1) << printAccounts(); | ||
| EXPECT_TRUE(buffer_factory_->waitForExpectedAccountUnregistered(1)) << printAccounts(); | ||
| } else { | ||
| EXPECT_EQ(buffer_factory_->numAccountsCreated(), 0); | ||
| EXPECT_TRUE(buffer_factory_->waitForExpectedAccountUnregistered(0)); | ||
| } | ||
| } | ||
|
|
||
| TEST_P(Http2BufferWatermarksTest, AccountsAndInternalRedirectWithRequestBody) { | ||
| Http::TestResponseHeaderMapImpl redirect_response_{ | ||
| {":status", "302"}, {"content-length", "0"}, {"location", "http://authority2/new/url"}}; | ||
|
|
||
| auto handle = config_helper_.createVirtualHost("handle.internal.redirect"); | ||
| handle.mutable_routes(0)->set_name("redirect"); | ||
| handle.mutable_routes(0)->mutable_route()->mutable_internal_redirect_policy(); | ||
| config_helper_.addVirtualHost(handle); | ||
| initialize(); | ||
|
|
||
| codec_client_ = makeHttpConnection(lookupPort("http")); | ||
|
|
||
| default_request_headers_.setHost("handle.internal.redirect"); | ||
| default_request_headers_.setMethod("POST"); | ||
|
|
||
| const std::string& request_body = "foobarbizbaz"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this shouldn't be a reference |
||
| buffer_factory_->setExpectedAccountBalance(request_body.size(), 1); | ||
|
|
||
| IntegrationStreamDecoderPtr response = | ||
| codec_client_->makeRequestWithBody(default_request_headers_, request_body); | ||
|
|
||
| waitForNextUpstreamRequest(); | ||
| upstream_request_->encodeHeaders(redirect_response_, true); | ||
|
|
||
| waitForNextUpstreamRequest(); | ||
|
|
||
| upstream_request_->encodeHeaders(default_response_headers_, true); | ||
|
|
||
| ASSERT_TRUE(response->waitForEndStream()); | ||
| ASSERT_TRUE(response->complete()); | ||
|
|
||
| if (streamBufferAccounting()) { | ||
| EXPECT_EQ(buffer_factory_->numAccountsCreated(), 1) << printAccounts(); | ||
| EXPECT_TRUE(buffer_factory_->waitForExpectedAccountUnregistered(1)) << printAccounts(); | ||
| EXPECT_TRUE( | ||
| buffer_factory_->waitForExpectedAccountBalanceWithTimeout(TestUtility::DefaultTimeout)) | ||
| << "buffer total: " << buffer_factory_->totalBufferSize() | ||
| << " buffer max: " << buffer_factory_->maxBufferSize() << printAccounts(); | ||
| } else { | ||
| EXPECT_EQ(buffer_factory_->numAccountsCreated(), 0); | ||
| EXPECT_TRUE(buffer_factory_->waitForExpectedAccountUnregistered(0)); | ||
| } | ||
| } | ||
|
|
||
| TEST_P(Http2BufferWatermarksTest, ShouldTrackAllocatedBytesToUpstream) { | ||
| const int num_requests = 5; | ||
| const uint32_t request_body_size = 4096; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: naming, should be
redirect_responsethe_suffix is reserved for object fields. Consider making const since it's not modified and shifting it down right where it's used.Same with above test.