From 6c5945310ce50e22451720460dff8aead5872c9e Mon Sep 17 00:00:00 2001 From: tonycpsu Date: Tue, 7 Apr 2026 23:07:15 -0400 Subject: [PATCH] Fix SQLiteException in resolveRecipient by checking cache before opening connection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit resolveRecipient(ServiceId) opens a pooled connection and starts a BEGIN IMMEDIATE transaction via setAutoCommit(false), then checks the in-memory cache. On a cache hit, the method returns early via try-with-resources, closing the connection without committing. When HikariCP reclaims the connection, it calls setAutoCommit(true) to reset it. The sqlite-jdbc driver unconditionally executes COMMIT at this point, but the transaction was already implicitly rolled back by SQLite when the connection was returned — causing: SQLiteException: [SQLITE_ERROR] cannot commit - no transaction is active This error corrupts the pooled connection state and causes subsequent operations to fail. Fix: check the cache before calling getConnection(). On cache hits, no connection is opened and no transaction is started. On cache misses, the existing behavior is preserved (open connection, BEGIN IMMEDIATE, resolve or create recipient, COMMIT). --- .../signal/manager/storage/recipients/RecipientStore.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/src/main/java/org/asamk/signal/manager/storage/recipients/RecipientStore.java b/lib/src/main/java/org/asamk/signal/manager/storage/recipients/RecipientStore.java index 044ba658..f59fcca6 100644 --- a/lib/src/main/java/org/asamk/signal/manager/storage/recipients/RecipientStore.java +++ b/lib/src/main/java/org/asamk/signal/manager/storage/recipients/RecipientStore.java @@ -184,12 +184,12 @@ public class RecipientStore implements RecipientIdCreator, RecipientResolver, Re @Override public RecipientId resolveRecipient(final ServiceId serviceId) { + final var recipientWithAddress = recipientAddressCache.get(serviceId); + if (recipientWithAddress != null) { + return recipientWithAddress.id(); + } try (final var connection = database.getConnection()) { connection.setAutoCommit(false); - final var recipientWithAddress = recipientAddressCache.get(serviceId); - if (recipientWithAddress != null) { - return recipientWithAddress.id(); - } final var recipientId = resolveRecipientLocked(connection, serviceId); connection.commit(); return recipientId;