@@ -1051,8 +1051,10 @@ ngx_stream_lua_run_thread(lua_State *L, ngx_stream_lua_request_t *r,
10511051 return NGX_AGAIN ;
10521052 }
10531053
1054- ngx_stream_lua_del_thread (r , L , ctx , ctx -> cur_co_ctx );
1055- ctx -> uthreads -- ;
1054+ if (ctx -> cur_co_ctx -> co_ref != LUA_NOREF ) {
1055+ ngx_stream_lua_del_thread (r , L , ctx , ctx -> cur_co_ctx );
1056+ ctx -> uthreads -- ;
1057+ }
10561058
10571059 if (ctx -> uthreads == 0 ) {
10581060 if (ngx_stream_lua_entry_thread_alive (ctx )) {
@@ -1090,7 +1092,9 @@ ngx_stream_lua_run_thread(lua_State *L, ngx_stream_lua_request_t *r,
10901092 lua_xmove (ctx -> cur_co_ctx -> co , next_co , nrets );
10911093 }
10921094
1093- if (ctx -> cur_co_ctx -> is_uthread ) {
1095+ if (ctx -> cur_co_ctx -> is_uthread
1096+ && ctx -> cur_co_ctx -> co_ref != LUA_NOREF )
1097+ {
10941098 ngx_stream_lua_del_thread (r , L , ctx , ctx -> cur_co_ctx );
10951099 ctx -> uthreads -- ;
10961100 }
@@ -1201,8 +1205,10 @@ ngx_stream_lua_run_thread(lua_State *L, ngx_stream_lua_request_t *r,
12011205 return NGX_AGAIN ;
12021206 }
12031207
1204- ngx_stream_lua_del_thread (r , L , ctx , ctx -> cur_co_ctx );
1205- ctx -> uthreads -- ;
1208+ if (ctx -> cur_co_ctx -> co_ref != LUA_NOREF ) {
1209+ ngx_stream_lua_del_thread (r , L , ctx , ctx -> cur_co_ctx );
1210+ ctx -> uthreads -- ;
1211+ }
12061212
12071213 if (ctx -> uthreads == 0 ) {
12081214 if (ngx_stream_lua_entry_thread_alive (ctx )) {
0 commit comments