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

lua: make sure resetting dynamic metadata wrapper when request info is marked dead #4312

Merged
merged 3 commits into from
Sep 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions source/extensions/filters/http/lua/wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ class RequestInfoWrapper : public Filters::Common::Lua::BaseLuaObject<RequestInf
*/
DECLARE_LUA_FUNCTION(RequestInfoWrapper, luaDynamicMetadata);

// Envoy::Lua::BaseLuaObject
void onMarkDead() override { dynamic_metadata_wrapper_.reset(); }

RequestInfo::RequestInfo& request_info_;
Filters::Common::Lua::LuaDeathRef<DynamicMetadataMapWrapper> dynamic_metadata_wrapper_;

Expand Down
36 changes: 36 additions & 0 deletions test/extensions/filters/http/lua/lua_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -342,5 +342,41 @@ name: envoy.lua
EXPECT_STREQ("200", response->headers().Status()->value().c_str());
}

// Should survive from 30 calls when calling requestInfo():dynamicMetadata(). This is a regression
// test for #4305.
TEST_P(LuaIntegrationTest, SurviveMultipleCalls) {
const std::string FILTER_AND_CODE =
R"EOF(
name: envoy.lua
config:
inline_code: |
function envoy_on_request(request_handle)
request_handle:requestInfo():dynamicMetadata()
end
)EOF";

initializeFilter(FILTER_AND_CODE);

codec_client_ = makeHttpConnection(makeClientConnection(lookupPort("http")));
Http::TestHeaderMapImpl request_headers{{":method", "GET"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "host"},
{"x-forwarded-for", "10.0.0.1"}};

for (uint32_t i = 0; i < 30; ++i) {
auto response = codec_client_->makeHeaderOnlyRequest(request_headers);

waitForNextUpstreamRequest();
upstream_request_->encodeHeaders(default_response_headers_, true);
response->waitForEndStream();

EXPECT_TRUE(response->complete());
EXPECT_STREQ("200", response->headers().Status()->value().c_str());
}

cleanup();
}

} // namespace
} // namespace Envoy