From b18476b443cca1efca419c8c479b56a449909aa9 Mon Sep 17 00:00:00 2001 From: xfy Date: Mon, 13 Apr 2026 09:51:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(lua):=20=E4=BF=AE=E5=A4=8D=E5=8D=8F?= =?UTF-8?q?=E7=A8=8B=E4=B8=8A=E4=B8=8B=E6=96=87=E8=AE=BE=E7=BD=AE=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用执行上下文(ExecutionContext)替代 RequestCtx 作为 LState 上下文, 因为 RequestCtx.Done() 依赖服务器连接状态,不适合用于超时控制。 RequestCtx 通过 coro.RequestCtx 字段访问。 Co-Authored-By: Claude Opus 4.6 --- internal/lua/engine.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/lua/engine.go b/internal/lua/engine.go index 3f64113..ae9c9aa 100644 --- a/internal/lua/engine.go +++ b/internal/lua/engine.go @@ -141,8 +141,10 @@ func (e *LuaEngine) NewCoroutine(req *fasthttp.RequestCtx) (*LuaCoroutine, error coro.CreatedAt = time.Now() coro.ExecutionContext, coro.executionCancel = context.WithTimeout(e.ctx, e.config.MaxExecutionTime) - // 设置 LState 的上下文,使 getRequestCtx 能够获取到 RequestCtx - co.SetContext(req) + // 设置 LState 的上下文为执行上下文(用于超时控制) + // 注意:不直接使用 RequestCtx,因为 RequestCtx.Done() 依赖服务器连接 + // RequestCtx 通过 coro.RequestCtx 字段访问,而不是 L.Context() + co.SetContext(coro.ExecutionContext) atomic.AddUint64(&e.stats.CoroutinesCreated, 1)