Skip to content

Commit

Permalink
Merge pull request #70 from MBogda/fix-stuck-sessions
Browse files Browse the repository at this point in the history
Fix: release sessions even in case of commit or rollback error.
  • Loading branch information
vgvoleg authored Dec 18, 2024
2 parents 0034d94 + 37740c2 commit 2a7a6e2
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions ydb_sqlalchemy/dbapi/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,24 @@ def begin(self):
self._maybe_await(self.tx_context.begin)

def commit(self):
if self.tx_context and self.tx_context.tx_id:
self._maybe_await(self.tx_context.commit)
self.tx_context = None
if self.session:
self._maybe_await(self.session_pool.release, self.session)
self.session = None
try:
if self.tx_context and self.tx_context.tx_id:
self._maybe_await(self.tx_context.commit)
self.tx_context = None
finally:
if self.session:
self._maybe_await(self.session_pool.release, self.session)
self.session = None

def rollback(self):
if self.tx_context and self.tx_context.tx_id:
self._maybe_await(self.tx_context.rollback)
self.tx_context = None
if self.session:
self._maybe_await(self.session_pool.release, self.session)
self.session = None
try:
if self.tx_context and self.tx_context.tx_id:
self._maybe_await(self.tx_context.rollback)
self.tx_context = None
finally:
if self.session:
self._maybe_await(self.session_pool.release, self.session)
self.session = None

def close(self):
self.rollback()
Expand Down

0 comments on commit 2a7a6e2

Please sign in to comment.