-
Notifications
You must be signed in to change notification settings - Fork 192
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
Database connections remain, even after switching profiles with load_profile(..., allow_switch=True)
#5506
Comments
tagging @ltalirz at his request. |
Pinging @chrisjsewell - do you happen to know what is going on here? |
Heya, well as @jbweston notes the unload-> close should indeed close all connections, so nothing immediately comes to mind. You could try looking at the You could also try changing the sqlalchemy logging to |
Here's another datapoint: adding |
Thanks a lot for investigating @jbweston ! Do I understand correctly that this means there is a reference cycle that isn't being garbage-collected automatically/fast enough? Is anybody opposed to adding an explicit aiida-core/aiida/manage/manager.py Lines 152 to 155 in a8b3da3
If not, I'm happy to prepare a PR, maybe even with a test :-) It seems to me that we don't need to worry about possible performance overheads for this operation, and clearing out the remaining sessions seems important. |
I confirm that after |
Describe the bug
Switching profiles from
profile-a
toprofile-b
withaiida.load_profile('profile-b', allow_switch=True)
does not close all connections to the database ofprofile-a
. This can be verified by trying to deleteprofile-a
after loadingprofile-b
:Steps to reproduce
Create 2 fresh profiles,
profile-a
andprofile-b
withverdi quicksetup
, then run the following script:Here's me running this in a jupyter notebook (but running it in a regular Python interpreter from the commandline gives the same result):
Expected behavior
I would expect switching profiles to close all connections to the database, and to be able to delete a profile once it has been unloaded.
Your environment
Additional context
I find this behavior very confusing: unloading the profile invokes the
close()
method ofPsqlDosBackend
, and that method indeed seems to close all connections and properly calldispose
on the sqlalchemy engine:aiida-core/aiida/storage/psql_dos/backend.py
Lines 112 to 122 in 63b4c4b
Maybe there are extra sessions that are created elsewhere, which we are not tracking, and
dispose
maybe doesn't do anything until those are closed?The text was updated successfully, but these errors were encountered: