From 57acd60cff4df26b1bb4b9fa5ddfa885b0dc074d Mon Sep 17 00:00:00 2001 From: Junyi Date: Thu, 23 Jul 2026 12:12:29 +0800 Subject: [PATCH] fix(auth): wait for token cleanup before shutdown (#10151) * fix(auth): wait for token cleanup before shutdown * fix(auth): avoid waiting for token cleanup on shutdown --------- Co-authored-by: xilesun <2013xile@gmail.com> --- .../src/server/token-controller.ts | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/plugins/@nocobase/plugin-auth/src/server/token-controller.ts b/packages/plugins/@nocobase/plugin-auth/src/server/token-controller.ts index ba57cde6733..7b7c3ed57c6 100644 --- a/packages/plugins/@nocobase/plugin-auth/src/server/token-controller.ts +++ b/packages/plugins/@nocobase/plugin-auth/src/server/token-controller.ts @@ -84,6 +84,14 @@ export class TokenController implements TokenControlService { }); } + private async cleanupSessionExpiredTokens(userId: number) { + try { + await this.removeSessionExpiredTokens(userId); + } catch (err) { + this.logger.error(err, { module: 'auth', submodule: 'token-controller', method: 'removeSessionExpiredTokens' }); + } + } + async add({ userId, authenticator }: { userId: number; authenticator?: string }) { const jti = randomUUID(); const currTS = Date.now(); @@ -97,15 +105,11 @@ export class TokenController implements TokenControlService { }; await this.setTokenInfo(jti, data); - try { - if (process.env.DB_DIALECT === 'sqlite') { - // SQLITE does not support concurrent operations - await this.removeSessionExpiredTokens(userId); - } else { - this.removeSessionExpiredTokens(userId); - } - } catch (err) { - this.logger.error(err, { module: 'auth', submodule: 'token-controller', method: 'removeSessionExpiredTokens' }); + if (process.env.DB_DIALECT === 'sqlite') { + // SQLITE does not support concurrent operations + await this.cleanupSessionExpiredTokens(userId); + } else { + this.cleanupSessionExpiredTokens(userId); } return data;