From f1c5c86bd3085fbca953d9827476fd206c972957 Mon Sep 17 00:00:00 2001 From: Steffen Waldmann Date: Wed, 26 Aug 2026 13:15:04 +0200 Subject: [PATCH 1/3] fix: destroy connections on failed COMMIT/ROLLBACK/BEGIN MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … instead of releasing them, leaking dead connections --- db-service/lib/common/DatabaseService.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/db-service/lib/common/DatabaseService.js b/db-service/lib/common/DatabaseService.js index 388dcb46b..efcf0e292 100644 --- a/db-service/lib/common/DatabaseService.js +++ b/db-service/lib/common/DatabaseService.js @@ -71,7 +71,7 @@ class DatabaseService extends cds.Service { await this.set(new SessionContext(ctx)) await this.send('BEGIN') } catch (e) { - this.release() + await this.destroy() // set()/BEGIN may have left the connection in an unusable state, so don't return it to the pool throw e } return this @@ -82,8 +82,13 @@ class DatabaseService extends cds.Service { */ async commit() { if (!this.dbc) return - await this.send('COMMIT') - this.release() // only release on successful commit as otherwise released on rollback + try { + await this.send('COMMIT') + this.release() // only release on successful commit as otherwise released on rollback + } catch (e) { + await this.destroy() // COMMIT may have left the connection in an unusable state, so don't return it to the pool + throw e + } } /** @@ -93,8 +98,10 @@ class DatabaseService extends cds.Service { if (!this.dbc) return try { await this.send('ROLLBACK') - } finally { this.release() + } catch (e) { + await this.destroy() // ROLLBACK may have left the connection in an unusable state, so don't return it to the pool + throw e } } From 9064cc3baef7a4ce7bbe92892ac0602d13b97cbb Mon Sep 17 00:00:00 2001 From: Steffen Waldmann Date: Fri, 28 Aug 2026 11:48:32 +0200 Subject: [PATCH 2/3] remove comments --- db-service/lib/common/DatabaseService.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/db-service/lib/common/DatabaseService.js b/db-service/lib/common/DatabaseService.js index efcf0e292..acf4d0d7d 100644 --- a/db-service/lib/common/DatabaseService.js +++ b/db-service/lib/common/DatabaseService.js @@ -71,7 +71,7 @@ class DatabaseService extends cds.Service { await this.set(new SessionContext(ctx)) await this.send('BEGIN') } catch (e) { - await this.destroy() // set()/BEGIN may have left the connection in an unusable state, so don't return it to the pool + await this.destroy() throw e } return this @@ -84,9 +84,9 @@ class DatabaseService extends cds.Service { if (!this.dbc) return try { await this.send('COMMIT') - this.release() // only release on successful commit as otherwise released on rollback + this.release() } catch (e) { - await this.destroy() // COMMIT may have left the connection in an unusable state, so don't return it to the pool + await this.destroy() throw e } } @@ -100,7 +100,7 @@ class DatabaseService extends cds.Service { await this.send('ROLLBACK') this.release() } catch (e) { - await this.destroy() // ROLLBACK may have left the connection in an unusable state, so don't return it to the pool + await this.destroy() throw e } } From a4edd56de4e221b734cd5d0c16d27a0ae2f75f74 Mon Sep 17 00:00:00 2001 From: Steffen Waldmann Date: Wed, 2 Sep 2026 16:48:49 +0200 Subject: [PATCH 3/3] don't re-throw on rollback --- db-service/lib/common/DatabaseService.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db-service/lib/common/DatabaseService.js b/db-service/lib/common/DatabaseService.js index acf4d0d7d..0989105b2 100644 --- a/db-service/lib/common/DatabaseService.js +++ b/db-service/lib/common/DatabaseService.js @@ -99,9 +99,9 @@ class DatabaseService extends cds.Service { try { await this.send('ROLLBACK') this.release() - } catch (e) { + } catch { + // don't re-throw: rollback() is the error handler in .then(commit, rollback) await this.destroy() - throw e } }