Skip to content

Commit

Permalink
Merge pull request #7945 from kozlovsky/fix/python10-access-violation
Browse files Browse the repository at this point in the history
Close database connections after exiting from the db_session to avoid access violation on Python 3.10
  • Loading branch information
kozlovsky committed Mar 27, 2024
2 parents 0b2a6a8 + a84ba12 commit b7c4bd2
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(self, connection, cache=None):
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.
self.pool.disconnect()


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

0 comments on commit b7c4bd2

Please sign in to comment.