Repository navigation
wasm: fix race condition on listener info in contexts. - #17243
Conversation
lambdai
left a comment
There was a problem hiding this comment.
Lifetime of listener metadata LGTM
|
@PiotrSikora What does Wasm spec say here? There are some significant repercussions on how we share roots since caches are generally stored there. Stats filter in istio, for example, keeps track of request reports in the root and (theoretically) benefits from sharing. I remember that the big change was making sure that listener reloads create new roots to avoid immediate config application. If we have multiple listeners reloading, how do we make sharing work? |
|
@mathetake thanks for the fast turnaround on the fix and detailed description of the changes in this PR, that's really helpful! While this PR looks fine code-wise, I'd prefer if we didn't introduce changes breaking existing Wasm extensions. Making listener info unavailable in the root context also doesn't seem like a desireable outcome. The original intent was always to create a separate root context for each unique configuration, with multiple Envoy filters configured exactly the same way being backed by a single root context inside the WasmVM. Currently, "unique configuration" is keyed only on Alternatively, we could change the mapping and create a separate root context for each configured Envoy filter, which I think could be easier to reason about to the users, but as @kyessenov pointed out, we'd lose the benefit of sharing root context across multiple (potentially thousands) identially configured Envoy filters, which might be quite costly at scale. |
OK that would work and make sense to me. Let me rework this PR and create the corresponding one to C++ host. (Sorry in advance I won't be available until tomorrow morning in UTC+9 so don't expect me to turnaround in the next 24 hours) |
Signed-off-by: Takeshi Yoneda <[email protected]>
00a45f4 to
16874aa
Compare
|
OK reworked this PR, and created the necessary change in C++ host: proxy-wasm/proxy-wasm-cpp-host#178 |
PiotrSikora
left a comment
There was a problem hiding this comment.
LGTM, but could you verify that this fixes the issue in Istio Proxy before we merge it? Thanks!
Signed-off-by: Takeshi Yoneda <[email protected]>
|
verified that the original issue Istio faced disappeared! |
Signed-off-by: Takeshi Yoneda <[email protected]>
|
ping @moderation for dep:) |
|
/lgtm deps |
) This is the follow up on envoyproxy#16795. ## Bug description If the same plugin/rootcontext is shared across multiple listeners, then there is a race in listener information. Before envoyproxy#16795, this was not a problem for stream contexts since given listener information is from *where* it is created (`Plugin: plugin_` member created in the factory instance) https://github.com/envoyproxy/envoy/pull/16795/files#diff-90e133f83d91e5c22d1f7c7e8c0cf8017536a23765978bf81c7efd0482be0d81L43 But after that being merged, the `Plugin` passed to stream context constructor is the one from `PluginHandle::plugin()` which is potentially shared across multiple listeners. For root contexts, this has been a problem since the beginning because the root context has been already potentially shared across multiple listeners, and pointing to the listener's info which is created first. ## Change in this PR Combined with proxy-wasm/proxy-wasm-cpp-host#178, we explicitly include listener information into the plugin key so that if two plugins have different info to each other, different plugin instances will be created. ## Note - Maybe we could drop the support for sharing 1 Plugin across multiple listeners (or filters), then this race condition would be resolved in a different way. I think it is worth discussion. - This race is originally reported by Istio istio/proxy#3395 (comment) Signed-off-by: Takeshi Yoneda <[email protected]>
Commit Message: wasm: fix multiple bug of vm key and plugin key calculation Additional Description: This PR fixed tow bugs of wasm vm cache key and wasm plugin cache key: - now, the whole PluginConfig will be used to calculate the cache key. Before this change, the plugins with different `allow_on_headers_stop_iteration` may hit same cached plugin handle and make unexpected behavior. - now, the `capability_restriction_config` and `runtime` will be used to calculate the vm cache key. Before this change, the plugin VMs with different `capability_restriction_config` and `runtime` may hit same cache and result in unexpected behavior. --- Now, we also removed the traffic direction from the plugin cache key. It's safe because it's unnecessary now. Long time ago, before the #31365, we cannot extract the listener info from the connection info, so the WASM will get the traffic direction and listener metadata from the FactoryContext and store the reference at the cached plugin. Then when `get_property` ABI is used, the plugin could serve the related attributes. And to avoid the wasm plugins that be configured in different listeners (with different direction/metadata) hit same plugin cache, we added the listener metadata and traffic direction in to plugin cache key calculation at #17243. But at the #36619 , we have did a great refactoring and removed the dependencies to the traffic direction and listener metadata from the FactoryContext. The `get_property` ABI will get attributes from the stream info and stream level context. So, after that, it's unnecessary to use the listener metadata and traffic direction as cache key. And at the #36941, we removed the traffic direction and listener metadata from the cached plugin completely. After that, the traffic direction/metadata make nonsense in the cache key. Risk Level: low. Testing: n/a. Docs Changes: n/a. Release Notes: added. Platform Specific Features: n/a. --------- Signed-off-by: wbpcode <[email protected]>
This is the follow up on #16795.
Bug description
If the same plugin/rootcontext is shared across multiple listeners, then there is a race in listener information.
Before #16795, this was not a problem for stream contexts since given listener information is from where it is created (
Plugin: plugin_member created in the factory instance) https://github.com/envoyproxy/envoy/pull/16795/files#diff-90e133f83d91e5c22d1f7c7e8c0cf8017536a23765978bf81c7efd0482be0d81L43But after that being merged, the
Pluginpassed to stream context constructor is the one fromPluginHandle::plugin()which is potentially shared across multiple listeners.For root contexts, this has been a problem since the beginning because the root context has been already potentially shared across multiple listeners, and pointing to the listener's info which is created first.
Change in this PR
Combined with proxy-wasm/proxy-wasm-cpp-host#178, we explicitly include listener information into the plugin key so that if two plugins have different info to each other, different plugin instances will be created.
Note
Signed-off-by: Takeshi Yoneda [email protected]