-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes MAISTRA-2550: Port of envoyproxy/envoy#14478. Currently when th…
…e ServerFactoryContext is passed to bootstrap extensions, it is only partially initialized. Specifically, attempting to access the cluster manager will cause a nullptr access (and hence a crash) (#102) This PR splits the creation and initialized to 2 seperate fucntions. Early creation is required to not break the `default_socket_interface` feature. Once created, the extension will receive the ServerFactoryContext in a different callback (the newly added `serverInitialized`), once they are fully initialized. Commit Message: Fix a crash that happens when bootstrap extensions perform http calls. Additional Description: Risk Level: Low (small bug-fix) Testing: Unit tests updated; tested manually with the changes as well. Docs Changes: N/A Release Notes: N/A Fixes envoyproxy/envoy#14420 Signed-off-by: Yuval Kohavi <yuval.kohavi@gmail.com> Signed-off-by: Dmitri Dolguikh <ddolguik@redhat.com>
- Loading branch information
Dmitri Dolguikh
authored
Aug 3, 2021
1 parent
947302d
commit 8440654
Showing
17 changed files
with
247 additions
and
40 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// NOLINT(namespace-envoy) | ||
#include <string> | ||
|
||
#include "proxy_wasm_intrinsics.h" | ||
|
||
template <typename T> std::unique_ptr<T> wrap_unique(T* ptr) { return std::unique_ptr<T>(ptr); } | ||
|
||
START_WASM_PLUGIN(WasmHttpCpp) | ||
|
||
// Required Proxy-Wasm ABI version. | ||
WASM_EXPORT(void, proxy_abi_version_0_1_0, ()) {} | ||
|
||
WASM_EXPORT(uint32_t, proxy_on_configure, (uint32_t, uint32_t)) { | ||
proxy_set_tick_period_milliseconds(100); | ||
return 1; | ||
} | ||
|
||
WASM_EXPORT(void, proxy_on_tick, (uint32_t)) { | ||
HeaderStringPairs headers; | ||
headers.push_back(std::make_pair<std::string, std::string>(":method", "GET")); | ||
headers.push_back(std::make_pair<std::string, std::string>(":path", "/")); | ||
headers.push_back(std::make_pair<std::string, std::string>(":authority", "example.com")); | ||
headers.push_back(std::make_pair<std::string, std::string>("x-test", "test")); | ||
HeaderStringPairs trailers; | ||
uint32_t token; | ||
WasmResult result = makeHttpCall("wasm_cluster", headers, "", trailers, 10000, &token); | ||
// We have sent successfully, stop timer - we only want to send one request. | ||
if (result == WasmResult::Ok) { | ||
proxy_set_tick_period_milliseconds(0); | ||
} | ||
} | ||
|
||
WASM_EXPORT(void, proxy_on_http_call_response, (uint32_t, uint32_t, uint32_t headers, uint32_t, uint32_t)) { | ||
if (headers != 0) { | ||
auto status = getHeaderMapValue(WasmHeaderMapType::HttpCallResponseHeaders, "status"); | ||
if ("200" == status->view()) { | ||
proxy_set_tick_period_milliseconds(0); | ||
return; | ||
} | ||
} | ||
// Request failed - very possibly because of the integration test not being ready. | ||
// Try again to prevent flakes. | ||
proxy_set_tick_period_milliseconds(100); | ||
} | ||
|
||
END_WASM_PLUGIN |
This file contains 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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#include "extensions/common/wasm/wasm.h" | ||
|
||
#include "test/extensions/common/wasm/wasm_runtime.h" | ||
#include "test/integration/http_protocol_integration.h" | ||
|
||
#include "gtest/gtest.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace Wasm { | ||
namespace { | ||
|
||
class WasmIntegrationTest : public HttpIntegrationTest, public testing::TestWithParam<std::string> { | ||
public: | ||
WasmIntegrationTest() | ||
: HttpIntegrationTest(Http::CodecClient::Type::HTTP1, Network::Address::IpVersion::v4) {} | ||
|
||
void createUpstreams() override { | ||
HttpIntegrationTest::createUpstreams(); | ||
addFakeUpstream(FakeHttpConnection::Type::HTTP1); | ||
} | ||
|
||
void cleanup() { | ||
if (wasm_connection_ != nullptr) { | ||
ASSERT_TRUE(wasm_connection_->close()); | ||
ASSERT_TRUE(wasm_connection_->waitForDisconnect()); | ||
} | ||
cleanupUpstreamAndDownstream(); | ||
} | ||
void initialize() override { | ||
auto httpwasm = TestEnvironment::substitute( | ||
"{{ test_rundir }}/test/extensions/bootstrap/wasm/test_data/http_cpp.wasm"); | ||
config_helper_.addConfigModifier([](envoy::config::bootstrap::v3::Bootstrap& bootstrap) { | ||
auto* wasm = bootstrap.mutable_static_resources()->add_clusters(); | ||
wasm->MergeFrom(bootstrap.static_resources().clusters()[0]); | ||
wasm->set_name("wasm_cluster"); | ||
}); | ||
|
||
config_helper_.addBootstrapExtension(fmt::format(R"EOF( | ||
name: envoy.filters.http.wasm | ||
typed_config: | ||
'@type': type.googleapis.com/envoy.extensions.wasm.v3.WasmService | ||
singleton: true | ||
config: | ||
name: "singleton" | ||
root_id: "singleton" | ||
configuration: | ||
'@type': type.googleapis.com/google.protobuf.StringValue | ||
value: "" | ||
vm_config: | ||
vm_id: "my_vm_id" | ||
runtime: "envoy.wasm.runtime.{}" | ||
code: | ||
local: | ||
filename: {} | ||
)EOF", | ||
GetParam(), httpwasm)); | ||
HttpIntegrationTest::initialize(); | ||
} | ||
|
||
FakeHttpConnectionPtr wasm_connection_; | ||
FakeStreamPtr wasm_request_; | ||
IntegrationStreamDecoderPtr response_; | ||
}; | ||
|
||
INSTANTIATE_TEST_SUITE_P(Runtimes, WasmIntegrationTest, | ||
Envoy::Extensions::Common::Wasm::sandbox_runtime_values, | ||
Envoy::Extensions::Common::Wasm::wasmTestParamsToString); | ||
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(WasmIntegrationTest); | ||
|
||
TEST_P(WasmIntegrationTest, FilterMakesCallInConfigureTime) { | ||
initialize(); | ||
ASSERT_TRUE(fake_upstreams_.back()->waitForHttpConnection(*dispatcher_, wasm_connection_)); | ||
|
||
// Expect the filter to send us an HTTP request | ||
ASSERT_TRUE(wasm_connection_->waitForNewStream(*dispatcher_, wasm_request_)); | ||
ASSERT_TRUE(wasm_request_->waitForEndStream(*dispatcher_)); | ||
|
||
EXPECT_EQ("test", wasm_request_->headers() | ||
.get(Envoy::Http::LowerCaseString("x-test"))[0] | ||
->value() | ||
.getStringView()); | ||
|
||
// Respond back to the filter. | ||
Http::TestResponseHeaderMapImpl response_headers{ | ||
{":status", "200"}, | ||
}; | ||
wasm_request_->encodeHeaders(response_headers, true); | ||
cleanup(); | ||
} | ||
|
||
} // namespace | ||
} // namespace Wasm | ||
} // namespace Extensions | ||
} // namespace Envoy |
This file contains 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
Oops, something went wrong.