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>
This commit is contained in:
Junyi
2026-07-23 12:12:29 +08:00
committed by GitHub
parent fae870e774
commit 57acd60cff
@@ -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;