From 2ba7e24842af63e4e630bf55a236e6b1ad686dd3 Mon Sep 17 00:00:00 2001 From: Renato Alcara Date: Wed, 4 Mar 2026 00:49:04 -0300 Subject: [PATCH] fix: add try/catch to delayed PreKey deletion to prevent unhandled rejection The setTimeout async callback in removePreKey could cause unhandled promise rejection if the keystore was destroyed (connection closed) before the 5-min grace period expired. Co-Authored-By: Claude Opus 4.6 --- src/Signal/libsignal.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Signal/libsignal.ts b/src/Signal/libsignal.ts index 5436dbea..8ef48a8f 100644 --- a/src/Signal/libsignal.ts +++ b/src/Signal/libsignal.ts @@ -847,7 +847,11 @@ function signalStorage( // Schedule deletion after grace period const timer = setTimeout(async () => { pendingPreKeyDeletions.delete(keyId) - await keys.set({ 'pre-key': { [id]: null } }) + try { + await keys.set({ 'pre-key': { [id]: null } }) + } catch { + // Keystore may be destroyed if connection closed — safe to ignore + } }, PREKEY_GRACE_PERIOD_MS) pendingPreKeyDeletions.set(keyId, timer)