排查确认是 ngx_http_lua_subrequest_resume 中的ctx发生了变更,导致了出core,如下代码,标红了ctx出现的地方,除了通过ngx_http_get_module_ctx给ctx赋值,没有别的地方修改ctx的值了。
但诡异的是,ctx的值还是发生了变化。。
static ngx_int_tngx_http_lua_subrequest_resume(ngx_http_request_t *r){ lua_State *vm; ngx_int_t rc; ngx_connection_t *c; ngx_http_lua_ctx_t *ctx; ngx_http_lua_co_ctx_t *coctx;
ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module); if (ctx == NULL) { return NGX_ERROR; }
ctx->resume_handler = ngx_http_lua_wev_handler;
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "lua run subrequests done, resuming lua thread");
coctx = ctx->cur_co_ctx;
dd("nsubreqs: %d", (int) coctx->nsubreqs);
ngx_http_lua_handle_subreq_responses(r, ctx);
dd("free sr_statues/headers/bodies memory ASAP");
#if 1 ngx_pfree(r->pool, coctx->sr_statuses);
coctx->sr_statuses = NULL; coctx->sr_headers = NULL; coctx->sr_bodies = NULL; coctx->sr_flags = NULL;#endif
c = r->connection; vm = ngx_http_lua_get_lua_vm(r, ctx);
rc = ngx_http_lua_run_thread(vm, r, ctx, coctx->nsubreqs);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "lua run thread returned %d", rc);
if (rc == NGX_AGAIN) { return ngx_http_lua_run_posted_threads(c, vm, r, ctx); }
if (rc == NGX_DONE) { ngx_http_lua_finalize_request(r, NGX_DONE);
// core在此处 return ngx_http_lua_run_posted_threads(c, vm, r, ctx); }
/* rc == NGX_ERROR || rc >= NGX_OK */
if (ctx->entered_content_phase) { ngx_http_lua_finalize_request(r, rc); return NGX_DONE; }
return rc;}
ngx_http_lua_run_posted_threads(ngx_connection_t *c, lua_State *L, ngx_http_request_t *r, ngx_http_lua_ctx_t *ctx){ ngx_int_t rc; ngx_http_lua_posted_thread_t *pt;
for ( ;; ) { if (c->destroyed) { return NGX_DONE; }
pt = ctx->posted_threads; if (pt == NULL) { return NGX_DONE; }
ctx->posted_threads = pt->next;
ngx_http_lua_probe_run_posted_thread(r, pt->co_ctx->co, (int) pt->co_ctx->co_status);
if (pt->co_ctx->co_status != NGX_HTTP_LUA_CO_RUNNING) { continue; }
ctx->cur_co_ctx = pt->co_ctx;
rc = ngx_http_lua_run_thread(L, r, ctx, 0);
if (rc == NGX_AGAIN) { continue; }
if (rc == NGX_DONE) { ngx_http_lua_finalize_request(r, NGX_DONE); continue; }
/* rc == NGX_ERROR || rc >= NGX_OK */
if (ctx->entered_content_phase) { ngx_http_lua_finalize_request(r, rc); }
return rc; }
r->ctx[ngx_http_lua_module.ctx_index]
Hello!
--
--
邮件来自列表“openresty”,专用于技术讨论!
订阅: 请发空白邮件到 openresty+subscribe@googlegroups.com
发言: 请发邮件到 open...@googlegroups.com
退订: 请发邮件至 openresty+unsubscribe@googlegroups.com
归档: http://groups.google.com/group/openresty
官网: http://openresty.org/
仓库: https://github.com/agentzh/ngx_openresty
教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html