Skip to content

Commit

Permalink
Close database connections after exiting from the db_session to avoid…
Browse files Browse the repository at this point in the history
… access violation on Python 3.10
  • Loading branch information
kozlovsky committed Mar 27, 2024
1 parent f941b89 commit 1dbe9a4
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/tribler/core/utilities/pony_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,15 @@ def release_lock(self):
lock_hold_duration = time.time() - acquire_time
info.lock_hold_total_duration += lock_hold_duration

def release(provider, connection, cache=None):

Check failure on line 348 in src/tribler/core/utilities/pony_utils.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/tribler/core/utilities/pony_utils.py#L348

Method 'release' should have "self" as first argument
super().release(connection, cache)

# This method is called after exiting the db_session context manager. Usually, after db_session finishes,
# PonyORM releases the connection to the connection pool. However, if the thread finishes, the connection
# remains open. Later, if such a connection is garbage collected, it may lead to memory corruption errors.
# To avoid this, we close the connection after the db_session is over by calling the `disconnect` method.
provider.pool.disconnect()


db_session = TriblerDbSession()
orm.db_session = orm.core.db_session = db_session
Expand Down

0 comments on commit 1dbe9a4

Please sign in to comment.