-
Notifications
You must be signed in to change notification settings - Fork 5.5k
wasm: allow execution of multiple instances of the same plugin. #13753
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
Changes from 19 commits
697dc19
672c1ff
8d49c1d
9f98a40
60003c1
6f3392a
33f8b48
375b02d
8ad9cbd
3a89a49
2facb41
4c0ed76
88d5dc0
40015d0
e94fd82
6d978fc
62a015e
487d930
930282d
cd04f3b
9965dcd
f16ba7d
3d4e28e
d128aaf
7bc7c9a
e15e498
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,13 @@ | ||
| #include "extensions/filters/http/wasm/wasm_filter.h" | ||
|
|
||
| #include "envoy/http/codes.h" | ||
|
|
||
| #include "common/buffer/buffer_impl.h" | ||
| #include "common/common/assert.h" | ||
| #include "common/common/enum_to_int.h" | ||
| #include "common/http/header_map_impl.h" | ||
| #include "common/http/message_impl.h" | ||
| #include "common/http/utility.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace HttpFilters { | ||
| namespace Wasm { | ||
|
|
||
| FilterConfig::FilterConfig(const envoy::extensions::filters::http::wasm::v3::Wasm& config, | ||
| Server::Configuration::FactoryContext& context) | ||
| : tls_slot_(context.threadLocal().allocateSlot()) { | ||
| : tls_slot_(ThreadLocal::TypedSlot<WasmHandle>::makeUnique(context.threadLocal())) { | ||
| plugin_ = std::make_shared<Common::Wasm::Plugin>( | ||
| config.config().name(), config.config().root_id(), config.config().vm_config().vm_id(), | ||
| config.config().vm_config().runtime(), | ||
|
|
@@ -26,15 +17,9 @@ FilterConfig::FilterConfig(const envoy::extensions::filters::http::wasm::v3::Was | |
| auto plugin = plugin_; | ||
| auto callback = [plugin, this](const Common::Wasm::WasmHandleSharedPtr& base_wasm) { | ||
| // NB: the Slot set() call doesn't complete inline, so all arguments must outlive this call. | ||
| tls_slot_->set( | ||
| [base_wasm, | ||
| plugin](Event::Dispatcher& dispatcher) -> std::shared_ptr<ThreadLocal::ThreadLocalObject> { | ||
| if (!base_wasm) { | ||
| return nullptr; | ||
| } | ||
| return std::static_pointer_cast<ThreadLocal::ThreadLocalObject>( | ||
| Common::Wasm::getOrCreateThreadLocalWasm(base_wasm, plugin, dispatcher)); | ||
| }); | ||
| tls_slot_->set([base_wasm, plugin](Event::Dispatcher& dispatcher) { | ||
| return Common::Wasm::getOrCreateThreadLocalWasm(base_wasm, plugin, dispatcher); | ||
| }); | ||
| }; | ||
|
|
||
| if (!Common::Wasm::createWasm( | ||
|
|
@@ -46,6 +31,17 @@ FilterConfig::FilterConfig(const envoy::extensions::filters::http::wasm::v3::Was | |
| } | ||
| } | ||
|
|
||
| FilterConfig::~FilterConfig() { | ||
| if (tls_slot_->currentThreadRegistered()) { | ||
|
Member
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. Same question.
Contributor
Author
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. Let's focus on this one: At startup: With config change at runtime: After Assert is hit with
Contributor
Author
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. OK, I've looked at all the other instances of Should I add a comment to say that cleanup is skipped during shutdown? Or do you want me to make some other changes?
Contributor
Author
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. There are reports of (From: istio/istio#28620)
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. RE cleanup during shutdown: why not just rely on the destructors for the objects held in the TLS slots?
Member
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. So, in the "early times" IIRC there used to be a shutdown() method for TLS objects that we would call to avoid this type of situation. Essentially we would give each TLS object a chance to clean itself up. I don't remember the history, but I removed it at some point because I determined all of the lifecycle stuff could be simplified because we destroy all TLS objects when shutdownThread() is called. So per @jmarantz why can't the TLS object constructor just do what it has to do when it's destroyed on the thread its owned by? For the aggregate cluster issue, it's possible there is a regression from some of the ref counting changes, but I think this is unrelated. Can you or someone else open a different issue on that with a complete callstack and whether it's happening during shutdown or not?
Contributor
Author
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. We're doing graceful shutdown of the Proxy-Wasm plugins within the WasmVM, so we cannot destroy them in-place, but I think that if I hold onto thread-local object representing RootContext instead of shared Plugin, then I might be able to dispatch this without |
||
| // Start graceful shutdown of Wasm plugin, unless Envoy is already shutting down. | ||
| tls_slot_->runOnAllThreads([plugin = plugin_](OptRef<WasmHandle> handle) { | ||
| if (handle.has_value()) { | ||
| handle->wasm()->startShutdown(plugin); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| } // namespace Wasm | ||
| } // namespace HttpFilters | ||
| } // namespace Extensions | ||
|
|
||
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.
Something about this seems broken. Why is this check here? On what thread is the WASM access log created and destroyed?