bugfix: prevent uthread crash by checking coroutine reference before …#2479
bugfix: prevent uthread crash by checking coroutine reference before …#2479oowl wants to merge 2 commits intoopenresty:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent user-thread (uthread) crashes during coroutine cleanup by only deleting threads (and decrementing ctx->uthreads) when the coroutine has a valid Lua registry reference (co_ref != LUA_NOREF).
Changes:
- Guard
ngx_http_lua_del_thread(...)+ctx->uthreads--withco_ref != LUA_NOREFin multiple uthread termination paths. - Adjust uthread cleanup logic to avoid acting on already-unreferenced coroutines.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| if (ctx->cur_co_ctx->is_uthread) { | ||
| if (ctx->cur_co_ctx->is_uthread | ||
| && ctx->cur_co_ctx->co_ref != LUA_NOREF) |
There was a problem hiding this comment.
The updated if around uthread cleanup lost its braces: ctx->uthreads--; is now outside the conditional, and there is still a closing } with no matching {, which will break compilation and (if fixed only syntactically) would decrement uthreads even when co_ref == LUA_NOREF. Please restore a braced block so both ngx_http_lua_del_thread(...) and ctx->uthreads-- are executed only when the current coroutine is an uthread with a valid co_ref.
| && ctx->cur_co_ctx->co_ref != LUA_NOREF) | |
| && ctx->cur_co_ctx->co_ref != LUA_NOREF) | |
| { |
| [alert] | ||
| lua tcp socket abort resolver | ||
| --- error_log | ||
|
|
…deletion
I hereby granted the copyright of the changes in this pull request
to the authors of this lua-nginx-module project.