From 2403d6cdc6a5c870f24d7a27e88cc7d87fc6d532 Mon Sep 17 00:00:00 2001 From: Wolfgang Kulhanek Date: Fri, 24 Oct 2025 15:07:09 +0200 Subject: [PATCH] Another token expiration fix. --- src/smapi.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/smapi.ts b/src/smapi.ts index 8034530..36d8305 100644 --- a/src/smapi.ts +++ b/src/smapi.ts @@ -250,11 +250,10 @@ class SonosSoap { logger.debug("Current tokens: " + JSON.stringify(this.tokenStore.getAll())); return this.tokenStore.get(token); } - associateCredentialsForToken(token: string, fullSmapiToken: SmapiToken, oldToken?:string) { + associateCredentialsForToken(token: string, fullSmapiToken: SmapiToken) { logger.debug("Adding token: " + token + " " + JSON.stringify(fullSmapiToken)); - if(oldToken) { - this.tokenStore.delete(oldToken); - } + // Don't immediately delete old token to avoid race conditions + // The cleanup process will handle expired tokens later this.tokenStore.set(token, fullSmapiToken); } } @@ -488,11 +487,9 @@ function bindSmapiSoapServiceToExpress( const swapToken = (expiredToken: string | undefined) => (newToken: SmapiToken) => { logger.debug("oldToken: " + expiredToken); logger.debug("newToken: " + JSON.stringify(newToken)); - if (expiredToken) { - sonosSoap.associateCredentialsForToken(newToken.token, newToken, expiredToken); - } else { - sonosSoap.associateCredentialsForToken(newToken.token, newToken); - } + // Always add the new token, but don't immediately delete the old one + // to avoid race conditions where Sonos might still be using the old token + sonosSoap.associateCredentialsForToken(newToken.token, newToken); return TE.right(newToken); }