-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Kong's interaction with binary nginx access modules #594
Comments
Thanks for bringing this up, I'll take a look at changing it, but you can also submit your changes via a PR! |
I've created a pull request names "Issue 594" to address this issue. |
May I ask how exactly are you exiting from your module? For example with lua-nginx-module, if you call |
Here's a snippet of the code of my binary nginx module. It's really a binary handler, written in C and compiled into nginx. It has nothing to do with The ngx_module_t ngx_http_check_digest_module = {
NGX_MODULE_V1, &module_ctx, NULL, NGX_HTTP_MODULE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NGX_MODULE_V1_PADDING
};
static ngx_http_module_t module_ctx = {
NULL, &hook_setup, NULL, NULL, NULL, NULL, NULL, NULL
};
static ngx_int_t hook_setup(ngx_conf_t *cf) {
ngx_http_handler_pt *h;
ngx_http_core_main_conf_t *cmcf;
cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
h = ngx_array_push(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers);
if (NULL == h)
return NGX_ERROR;
*h = &handler;
return NGX_OK;
}
static ngx_int_t handler(ngx_http_request_t *r) {
/* most of the time this function returns NGX_DECLINED */
/* but sometimes it returns NGX_HTTP_UNAUTHORIZED */
/* the function does not modify any field of the ngx_http_request_t structure */
return NGX_HTTP_UNAUTHORIZED;
} |
Yes, it was my understanding already. I will see into this. |
I've compiled nginx with debug symbols and I get the stack trace below. So the
|
I have compiled OpenResty with a similar module, found the issue, and will provide a fix for it in the |
#708 now handles this properly, and I ended up refactoring Thank you for reporting this! |
Hello,
I have a custom nginx access module. It executes before the lua module and sometimes it returns HTTP_UNAUTHORIZED. When this happens I get no response whatsoever from Kong (no headers, no body, the http connection is just closed). I get the following error in the logs:
failed to run header_filter_by_lua*: /usr/local/share/lua/5.1/kong.lua:218: attempt to index field 'plugin' (a nil value)
I suspect the following happens: the access_by_lua set by Kong is not executed any more => some ngx.ctx variables (ngx.ctx.api or ngx.ctx.stop_phases for example) are not set => they are checked/used later, for example in the {header|body}_filter_by_lua callbacks and, as they are not defined, those ngx.ctx variables cause errors in the lua interpreter.
I have replaced
if not ngx.ctx.stop_phases then
byif ngx.ctx.stop_phases ~= nil and not ngx.ctx.stop_phases then
in the exec_plugins_{header|body}_filter in kong.lua and now I'm getting normal responses from kong, i.e. I'm getting the 401 Unauthorized header with the corresponding error message from nginx.I propose that all kong lua callbacks check first for the existence of one ngx.ctx.api or ngx.ctx.plugin or ngx.ctx.stop_phases before taking action.
The text was updated successfully, but these errors were encountered: