Repository navigation
wasm: pass PluginHandle to stream contexts. - #16795
Conversation
Signed-off-by: Takeshi Yoneda <[email protected]>
|
OK we need to pass the handle to ContexBase in C++ host so that VMs outlives not only Context (in Envoy) but also ContextBase (in Proxy-Wasm C++ host). |
Signed-off-by: Takeshi Yoneda <[email protected]>
|
tests will follow after #16430 |
Signed-off-by: Takeshi Yoneda <[email protected]>
Signed-off-by: Takeshi Yoneda <[email protected]>
Signed-off-by: Takeshi Yoneda <[email protected]>
Signed-off-by: Takeshi Yoneda <[email protected]>
e132459 to
412081d
Compare
|
/retest |
|
Retrying Azure Pipelines: |
|
I think Lizan's out for a bit, so @PiotrSikora can you do first pass, and tag Matt or I when it's ready for merge? |
Signed-off-by: Takeshi Yoneda <[email protected]>
|
@PiotrSikora still need a non-Tetrands review from you |
Sorry, I spent way too much time doing archeology work on this issue trying to find a regression, and then looking for an alternative solution. I should have timed out on this much sooner, I'll wrap this within next 24 hours. |
PiotrSikora
left a comment
There was a problem hiding this comment.
Thanks, and sorry for the delay!
Signed-off-by: Takeshi Yoneda <[email protected]>
Signed-off-by: Takeshi Yoneda <[email protected]>
|
@moderation PTAL for dep! |
|
/lgtm deps |
|
@lizan I believe we are good to go now |
Previously, stream contexts (i.e. filter instances) are not holding shared ptrs to Wasm plugins which take ownership of Wasm VMs, and only holding raw pointers to Wasm VMs. If Wasm plugins (i.e. factory) die earlier than stream contexts during ECDS updates, then the left stream contexts will try using invalidated pointers to Wasm VM and this results in crashes. So this commit passes the PluginHandle to all the stream contexts which the plugin generates, so the VM must outlive all stream contexts by which it is used. Counter part in Proxy-Wasm C++ Host: proxy-wasm/proxy-wasm-cpp-host#167 Resolves istio/istio#33091 Signed-off-by: Takeshi Yoneda <[email protected]> Signed-off-by: chris.xin <[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-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]>
Previously, stream contexts (i.e. filter instances) are not holding shared ptrs to Wasm plugins which take ownership of Wasm VMs, and only holding raw pointers to Wasm VMs. If Wasm plugins (i.e. factory) die earlier than stream contexts during ECDS updates, then the left stream contexts will try using invalidated pointers to Wasm VM and this results in crashes. So this commit passes the PluginHandle to all the stream contexts which the plugin generates, so the VM must outlive all stream contexts by which it is used. Counter part in Proxy-Wasm C++ Host: proxy-wasm/proxy-wasm-cpp-host#167 Resolves istio/istio#33091 Signed-off-by: Takeshi Yoneda <[email protected]>
) 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]>
Envoy requires node.id and node.cluster for any xDS config subscription, including filesystem-based ones. Envoy's subscriptionFromConfigSource checks node identity before examining the config source type, so path_config_source crashes the same way gRPC does. This blocks any extension that uses Extension Configuration Discovery Service (ECDS), Secret Discovery Service (SDS) for TLS certs, or any other dynamic config. For example, Istio uses ECDS to hot-reload Wasm filters on running sidecars (envoyproxy/envoy#16795). With nativeHttpFilters.after, a Go dynamic module can do the same thing locally: generate ECDS config at init and write it to disk for a native filter to consume via path_config_source. Signed-off-by: Adrian Cole <[email protected]>
Istio uses ECDS to hot-reload Wasm filters on running sidecars (envoyproxy/envoy#16795). With nativeHttpFilters.after, a Go dynamic module can do the same thing locally: generate Extension Configuration Discovery Service (ECDS) config at init and write it to disk for a native filter to consume via path_config_source. After that point, the module stays out of the request path entirely. In short, dynamic modules could be used to augment, share code with, or replace control plane (xDS) code, regardless of if that is about ECDS, Secret Discovery Service (SDS) for TLS certs and any other dynamic config. If you try this with BOE now, Envoy crashes on startup. Envoy requires node.id and node.cluster for any xDS config subscription. Set node to "boe" in buildFullConfig. Static configs that don't create subscriptions ignore node entirely, so there's no risk. Signed-off-by: Adrian Cole <[email protected]>
Istio [uses ECDS to hot-reload Wasm filters][istio-ecds] on running
sidecars without restarting Envoy. In BOE, using
[`nativeHttpFilters.after`][native-after], a dynamic module can do the
same thing locally: generate [Extension Configuration Discovery
Service][ecds] (ECDS) config at init and write it to disk for a native
filter to consume (via [`path_config_source`][path-config]). After that
point, the module stays out of the request path entirely.
In short, dynamic modules could be used to augment, share code with, or
replace control plane ([xDS][xds]) code. This is regardless of if that
is about ECDS, [Secret Discovery Service][sds] (SDS) for TLS certs, or
any other dynamic config.
If you try this with BOE now, envoy crashes on startup. Envoy requires
`node.id` and `node.cluster` for any
xDS config subscription. This simple change to enable this is set `node:
{id: "boe", cluster: "boe"}` in `buildFullConfig`. Static configs that
don't create subscriptions ignore node entirely, so there's no risk I'm
aware of.
[xds]: https://www.envoyproxy.io/docs/envoy/latest/api-docs/xds_protocol
[path-config]:
https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/core/v3/config_source.proto#config-core-v3-pathconfigsource
[ecds]:
https://www.envoyproxy.io/docs/envoy/latest/configuration/overview/extension#discovery-service
[sds]:
https://www.envoyproxy.io/docs/envoy/latest/configuration/security/secret
[istio-ecds]: envoyproxy/envoy#16795
[native-after]:
https://github.com/tetratelabs/built-on-envoy/blob/main/extensions/manifest.schema.json
Signed-off-by: Adrian Cole <[email protected]>
Previously, stream contexts (i.e. filter instances) are not holding shared ptrs to Wasm plugins which take ownership of Wasm VMs, and only holding raw pointers to Wasm VMs. If Wasm plugins (i.e. factory) die earlier than stream contexts during ECDS updates, then the left stream contexts will try using invalidated pointers to Wasm VM and this results in crashes.
So this commit passes the PluginHandle to all the stream contexts which the plugin generates, so the VM must outlive all stream contexts by which it is used.
Counter part in Proxy-Wasm C++ Host: proxy-wasm/proxy-wasm-cpp-host#167
Resolves istio/istio#33091
Signed-off-by: Takeshi Yoneda [email protected]
EDIT: I hope this commit 412081d explains the bug well.