diff --git a/src/ngx_http_lua_control.c b/src/ngx_http_lua_control.c index 1b7053c409..fefc8027ba 100644 --- a/src/ngx_http_lua_control.c +++ b/src/ngx_http_lua_control.c @@ -386,13 +386,18 @@ ngx_http_lua_on_abort(lua_State *L) lua_pushlightuserdata(L, &ngx_http_lua_coroutines_key); lua_rawget(L, LUA_REGISTRYINDEX); - lua_pushvalue(L, -3); + lua_pushvalue(L, -2); + + dd("on_wait thread 1: %p", lua_tothread(L, -1)); + coctx->co_ref = luaL_ref(L, -2); lua_pop(L, 1); coctx->is_uthread = 1; ctx->on_abort_co_ctx = coctx; + dd("on_wait thread 2: %p", coctx->co); + coctx->co_status = NGX_HTTP_LUA_CO_SUSPENDED; coctx->parent_co_ctx = ctx->cur_co_ctx; diff --git a/t/023-rewrite/on-abort.t b/t/023-rewrite/on-abort.t index 35d49be0c9..9c2ed5482a 100644 --- a/t/023-rewrite/on-abort.t +++ b/t/023-rewrite/on-abort.t @@ -68,7 +68,7 @@ lua req cleanup --- timeout: 0.2 --- abort ---- wait: 0.5 +--- wait: 0.6 --- ignore_response --- no_error_log [error] @@ -303,7 +303,7 @@ lua req cleanup --- timeout: 0.2 --- abort ---- wait: 0.5 +--- wait: 0.6 --- ignore_response --- error_log client prematurely closed connection diff --git a/t/101-on-abort.t b/t/101-on-abort.t index d3136d8d42..4d60acb053 100644 --- a/t/101-on-abort.t +++ b/t/101-on-abort.t @@ -20,7 +20,7 @@ our $StapScript = $t::StapThread::StapScript; repeat_each(2); -plan tests => repeat_each() * (blocks() * 4 + 18); +plan tests => repeat_each() * (blocks() * 4 + 16); $ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8'; $ENV{TEST_NGINX_MEMCACHED_PORT} ||= '11211'; @@ -293,7 +293,7 @@ lua req cleanup --- timeout: 0.2 --- abort ---- wait: 0.5 +--- wait: 0.6 --- ignore_response --- error_log client prematurely closed connection @@ -531,6 +531,7 @@ delete thread 2 delete thread 3 --- timeout: 0.2 +--- wait: 0.1 --- abort --- ignore_response --- no_error_log @@ -766,3 +767,24 @@ main handler done client prematurely closed connection on abort called + + +=== TEST 17: GC issue with the on_abort thread object +--- config + location = /t { + lua_check_client_abort on; + content_by_lua ' + ngx.on_abort(function () end) + collectgarbage() + ngx.sleep(60) + '; + } +--- request + GET /t +--- abort +--- timeout: 0.2 +--- ignore_response +--- no_error_log +[error] +[alert] +