Skip to content
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

ngx.exec ngx.ctx #20

Closed
techxel opened this issue Jul 7, 2017 · 1 comment
Closed

ngx.exec ngx.ctx #20

techxel opened this issue Jul 7, 2017 · 1 comment

Comments

@techxel
Copy link

techxel commented Jul 7, 2017

log_by_lua_block {
    local ctx = ngx.ctx
    local lim = ctx.limit_conn
    if lim then
        local latency = tonumber(ngx.var.request_time)
        local key = ctx.limit_conn_key
        assert(key)
        local conn, err = lim:leaving(key, latency)
        if not conn then
           ngx.log(ngx.ERR, err)
           return
        end
    end
}

如果我使用了ngx.exec进行了转发, 我该如何在log_by_lua_block中获取lim, 因为ngx.ctx已经销毁了?

@agentzh
Copy link
Member

agentzh commented Jul 7, 2017

@yin32167 Please, do not use Chinese here. This place is considered English only. If you
really want to use Chinese, please join and post to the openresty (Chinese)
mailing list instead. Please see https://openresty.org/en/community.html Thanks for
your cooperation.

Regarding your question, ngx.exec does clear all the context data of the original request handler. It's officially documented:

https://github.com/openresty/lua-nginx-module/#ngxctx

Please read the documentation carefully.

There does exist a workaround to make ngx.ctx persistent after the internal redirects proposed in the issue openresty/lua-nginx-module#1057

@agentzh agentzh closed this as completed Jul 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants