Kong / ngx_wasm_module

Nginx + WebAssembly
Apache License 2.0
80 stars 7 forks source link

fix(ffi) allow 'load()' to fail and be invoked again #525

Closed thibaultcha closed 5 months ago

thibaultcha commented 5 months ago

Before instantiating filter chains and request contexts, filters themselves (i.e. their root context) are represented in the module. Eventually, ngx_proxy_wasm_start iterates over all filters to start their root contexts.

Previously, all filters declared in proxy_wasm directives were stored globally. With the introduction of the FFI filters can be dynamically added to the internal representation during proxy_wasm.load, which makes it possible for ngx_proxy_wasm_start to be invoked several times.

However, since the filters structure was global then all previously declared filters were started again, including filters that previously failed initializing their root contexts. This was not happening with proxy_wasm directives since a filter failing initialization in that case would not allow Nginx to start in the first place.

Now all filters are stored in a "filters root" structure which can divide filter root contexts as needed. Each worker has a global "worker filters root", and each ngx_wasm_ops_plan created by the FFI has its own isolated "filters root".

codecov[bot] commented 5 months ago

Codecov Report

Merging #525 (5b4a361) into main (1d19282) will increase coverage by 0.01905%. The diff coverage is 96.22642%.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/Kong/ngx_wasm_module/pull/525/graphs/tree.svg?width=650&height=150&src=pr&token=T0PT2Q9IAN&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kong)](https://app.codecov.io/gh/Kong/ngx_wasm_module/pull/525?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kong) ```diff @@ Coverage Diff @@ ## main #525 +/- ## =================================================== + Coverage 89.99297% 90.01202% +0.01905% =================================================== Files 47 47 Lines 9953 9982 +29 =================================================== + Hits 8957 8985 +28 - Misses 996 997 +1 ``` | [Files](https://app.codecov.io/gh/Kong/ngx_wasm_module/pull/525?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kong) | Coverage Δ | | |---|---|---| | [src/common/proxy\_wasm/ngx\_proxy\_wasm.h](https://app.codecov.io/gh/Kong/ngx_wasm_module/pull/525?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kong#diff-c3JjL2NvbW1vbi9wcm94eV93YXNtL25neF9wcm94eV93YXNtLmg=) | `91.89189% <ø> (ø)` | | | [src/http/ngx\_http\_wasm\_directives.c](https://app.codecov.io/gh/Kong/ngx_wasm_module/pull/525?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kong#diff-c3JjL2h0dHAvbmd4X2h0dHBfd2FzbV9kaXJlY3RpdmVzLmM=) | `91.77215% <100.00000%> (+0.10548%)` | :arrow_up: | | [src/http/ngx\_http\_wasm\_module.c](https://app.codecov.io/gh/Kong/ngx_wasm_module/pull/525?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kong#diff-c3JjL2h0dHAvbmd4X2h0dHBfd2FzbV9tb2R1bGUuYw==) | `96.01874% <100.00000%> (+0.00934%)` | :arrow_up: | | [src/http/ngx\_http\_wasm\_util.c](https://app.codecov.io/gh/Kong/ngx_wasm_module/pull/525?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kong#diff-c3JjL2h0dHAvbmd4X2h0dHBfd2FzbV91dGlsLmM=) | `86.99187% <100.00000%> (+0.21501%)` | :arrow_up: | | [src/wasm/ngx\_wasm\_ops.c](https://app.codecov.io/gh/Kong/ngx_wasm_module/pull/525?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kong#diff-c3JjL3dhc20vbmd4X3dhc21fb3BzLmM=) | `92.12963% <100.00000%> (-0.07220%)` | :arrow_down: | | [src/common/lua/ngx\_wasm\_lua\_ffi.c](https://app.codecov.io/gh/Kong/ngx_wasm_module/pull/525?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kong#diff-c3JjL2NvbW1vbi9sdWEvbmd4X3dhc21fbHVhX2ZmaS5j) | `93.60000% <96.29630%> (+1.86445%)` | :arrow_up: | | [src/common/proxy\_wasm/ngx\_proxy\_wasm.c](https://app.codecov.io/gh/Kong/ngx_wasm_module/pull/525?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kong#diff-c3JjL2NvbW1vbi9wcm94eV93YXNtL25neF9wcm94eV93YXNtLmM=) | `92.53898% <93.75000%> (-0.30193%)` | :arrow_down: | ... and [1 file with indirect coverage changes](https://app.codecov.io/gh/Kong/ngx_wasm_module/pull/525/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kong) | [Flag](https://app.codecov.io/gh/Kong/ngx_wasm_module/pull/525/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kong) | Coverage Δ | | |---|---|---| | [unit](https://app.codecov.io/gh/Kong/ngx_wasm_module/pull/525/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kong) | `90.09224% <97.40260%> (+0.03629%)` | :arrow_up: | | [valgrind](https://app.codecov.io/gh/Kong/ngx_wasm_module/pull/525/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kong) | `78.00680% <98.03922%> (+0.04331%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Kong#carryforward-flags-in-the-pull-request-comment) to find out more.