From 77f568fdff61e934bcf43ab79e93c551e07b0ba9 Mon Sep 17 00:00:00 2001 From: "QCQCQC@Debian" Date: Wed, 10 Dec 2025 15:51:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= =?UTF-8?q?=E6=97=B6=E7=9A=84ctx=E6=9C=AA=E8=A2=AB=E6=AD=A3=E7=A1=AE?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/AppLoader.js | 8 ++++++-- src/AppLoader.ts | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/AppLoader.js b/lib/AppLoader.js index f9551c9..bf17670 100644 --- a/lib/AppLoader.js +++ b/lib/AppLoader.js @@ -59,13 +59,15 @@ class AppLoader extends types_1.AppLoader { const errorToPublish = (0, lodash_1.cloneDeep)(err); await Promise.all(this.internalErrorHandlers.map((handler) => { return new Promise(async (resolve) => { + const ctx = await this.makeContext(); try { - const ctx = await this.makeContext(); console.log(`调用internalErrorHandler【${handler.name}】处理内部错误事件`); - handler.handle(ctx, type, message, errorToPublish); + await handler.handle(ctx, type, message, errorToPublish); + await ctx.commit(); } catch (e) { console.error('执行internalErrorHandler时出错', e); + await ctx.rollback(); } finally { resolve(); @@ -532,6 +534,7 @@ class AppLoader extends types_1.AppLoader { try { const result = await routineFn(context, { socket: this.nsSocket, + contextBuilder: () => this.makeContext(), }); console.log(`例程【${name}】执行成功,耗时${Date.now() - start}毫秒,结果是【${result}】`); await context.commit(); @@ -566,6 +569,7 @@ class AppLoader extends types_1.AppLoader { try { const result = await routineFn(context, { socket: this.nsSocket, + contextBuilder: () => this.makeContext(), }); console.log(`例程【${name}】执行成功,耗时${Date.now() - start}毫秒,结果是【${result}】`); await context.commit(); diff --git a/src/AppLoader.ts b/src/AppLoader.ts index 0a91353..b3cf543 100644 --- a/src/AppLoader.ts +++ b/src/AppLoader.ts @@ -70,12 +70,14 @@ export class AppLoader { return new Promise(async (resolve) => { + const ctx = await this.makeContext(); try { - const ctx = await this.makeContext(); console.log(`调用internalErrorHandler【${handler.name}】处理内部错误事件`); - handler.handle(ctx, type, message, errorToPublish); + await handler.handle(ctx, type, message, errorToPublish); + await ctx.commit() } catch (e) { console.error('执行internalErrorHandler时出错', e); + await ctx.rollback(); } finally { resolve(); } @@ -625,6 +627,7 @@ export class AppLoader this.makeContext(), }); console.log(`例程【${name}】执行成功,耗时${Date.now() - start}毫秒,结果是【${result}】`); await context.commit(); @@ -661,6 +664,7 @@ export class AppLoader this.makeContext(), }); console.log(`例程【${name}】执行成功,耗时${Date.now() - start}毫秒,结果是【${result}】`); await context.commit();