Skip to content
New issue

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

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

Already on GitHub? # to your account

Close database connections after exiting from the db_session to avoid access violation on Python 3.10 #7945

Merged
merged 1 commit into from
Mar 27, 2024
Merged
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
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
Loading