8000 Fix connection leak when transaction commit/rollback raise an exception by masipcat · Pull Request #498 · encode/databases · GitHub
[go: up one dir, main page]

Skip to content

Fix connection leak when transaction commit/rollback raise an exception #498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
Fix connection leak when transaction commit/rollback raise an exception
  • Loading branch information
masipcat committed Jul 18, 2022
commit 0d3c5ae445c9576a6e208e7efd80a8c5c73be269
12 changes: 8 additions & 4 deletions databases/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,15 +371,19 @@ async def commit(self) -> None:
async with self._connection._transaction_lock:
assert self._connection._transaction_stack[-1] is self
self._connection._transaction_stack.pop()
await self._transaction.commit()
await self._connection.__aexit__()
try:
await self._transaction.commit()
finally:
await self._connection.__aexit__()

async def rollback(self) -> None:
async with self._connection._transaction_lock:
assert self._connection._transaction_stack[-1] is self
self._connection._transaction_stack.pop()
await self._transaction.rollback()
await self._connection.__aexit__()
try:
await self._transaction.rollback()
finally:
await self._connection.__aexit__()


class _EmptyNetloc(str):
Expand Down
0