Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions db-service/lib/common/DatabaseService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
throw e
}
return this
Expand All @@ -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()
} catch (e) {
await this.destroy()
throw e
}
}

/**
Expand All @@ -93,8 +98,10 @@ class DatabaseService extends cds.Service {
if (!this.dbc) return
try {
await this.send('ROLLBACK')
} finally {
this.release()
} catch {
// don't re-throw: rollback() is the error handler in .then(commit, rollback)
await this.destroy()
}
}

Expand Down