Skip to content

Commit

Permalink
lua: make sure resetting dynamic metadata wrapper when request info i…
Browse files Browse the repository at this point in the history
…s marked dead

This PR makes sure we reset dynamic metadata wrapper when its parent (request info wrapper) is marked dead.

Risk Level: Low
Testing: Add integration testing
Docs Changes: N/A
Release Notes: N/A
Fixes #4305

Signed-off-by: Dhi Aurrahman <[email protected]>
  • Loading branch information
dio authored and dnoe committed Sep 4, 2018
1 parent d243cd6 commit 1485a13
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
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

0 comments on commit 1485a13

Please sign in to comment.