Skip to content

bugfix: prevent uthread crash by checking coroutine reference before …#2479

Open
oowl wants to merge 2 commits intoopenresty:masterfrom
oowl:fix-uthread-crash
Open

bugfix: prevent uthread crash by checking coroutine reference before …#2479
oowl wants to merge 2 commits intoopenresty:masterfrom
oowl:fix-uthread-crash

Conversation

@oowl
Copy link
Contributor

@oowl oowl commented Mar 9, 2026

…deletion

I hereby granted the copyright of the changes in this pull request
to the authors of this lua-nginx-module project.

Copilot AI review requested due to automatic review settings March 9, 2026 15:23
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-- with co_ref != LUA_NOREF in 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)
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
&& ctx->cur_co_ctx->co_ref != LUA_NOREF)
&& ctx->cur_co_ctx->co_ref != LUA_NOREF)
{

Copilot uses AI. Check for mistakes.
[alert]
lua tcp socket abort resolver
--- error_log

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

three empty lines

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

Successfully merging this pull request may close these issues.

3 participants