Skip to content

Commit

Permalink
fix(proxy-wasm) load filter from lua - WasmX as module
Browse files Browse the repository at this point in the history
When WasmX is compiled as shared library and loaded into Nginx via
`load_module`, its modules will end up after `ngx_http_lua_module` in
`ngx_cycle->modules` list.

As a result, `ngx_http_lua_init_worker_by_inline` -- which might try to
load wasm filters -- is called before `ngx_wasm_core_init_process` -- which
prepares a wasm vm -- is ever called, causing the load to fail.
  • Loading branch information
casimiro committed Jun 21, 2023
1 parent ba8da72 commit b04b16a
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/wasm/ngx_wasm_core_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,38 @@ ngx_wasm_core_create_conf(ngx_conf_t *cf)
static const ngx_str_t runtime_name = ngx_string(NGX_WASM_RUNTIME);
static const ngx_str_t ip = ngx_string(NGX_WASM_DEFAULT_RESOLVER_IP);

#if (NGX_WASM_LUA)
ngx_uint_t lua_i, wasm_i, tmp_i;
ngx_module_t *lua_module = NULL; *wasm_module = NULL, *tmp;

for (lua_i = 0; cycle->modules[lua_i]; lua_i++) {
lua_module = cycle->modules[lua_i];
if (ngx_strcmp(lua_module->name, "ngx_http_lua_module") == 0) {
break;
}
}

for (wasm_i = lua_i + 1; cycle->modules[wasm_i]; wasm_i++) {
wasm_module = cycle->modules[wasm_i];
if (ngx_strcmp(wasm_module->name, "ngx_wasm_core_module") == 0) {
break;
}
}

/* cycle->modules[wasm_i] is NULL if execution order has been rectified */
if (cycle->modules[wasm_i] && cycle->modules[lua_i]) {
tmp = cycle->modules[lua_i];
tmp_i = cycle->modules[lua_i]->index;

cycle->modules[lua_i]->index = cycle->modules[wasm_i]->index;
cycle->modules[wasm_i]->index = tmp_i;

cycle->modules[lua_i] = cycle->modules[wasm_i];
cycle->modules[wasm_i] = tmp;

}
#endif

wcf = ngx_pcalloc(cycle->pool, sizeof(ngx_wasm_core_conf_t));
if (wcf == NULL) {
return NULL;
Expand Down

0 comments on commit b04b16a

Please sign in to comment.