Skip to content

File handles left open #287

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

Closed
afgane opened this issue May 11, 2015 · 9 comments
Closed

File handles left open #287

afgane opened this issue May 11, 2015 · 9 comments

Comments

@afgane
Copy link

afgane commented May 11, 2015

Hello,
It seems that as soon as I access any of the fields within r.head.commit, a set of file handles open and they don't close until the parent process exits. Specifically for me, this prevents me from unmounting a file system.

Here's an example of what I'm doing:

from git import Repo
r = Repo('/mnt/galaxy/galaxy-app')
r.head.commit.hexsha

As soon as a commit object field is accessed, the following happens on the file system:

$ sudo lsof +D /mnt/galaxy
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF     NODE NAME
ipython 29619 root  mem    REG 202,80 54593196 33598181 /mnt/galaxy/galaxy-app/.git/objects/pack/pack-c5d4b5abfd9295af7aea34651359d8b056c6a1af.pack
ipython 29619 root  mem    REG 202,80  4668532 33598182 /mnt/galaxy/galaxy-app/.git/objects/pack/pack-c5d4b5abfd9295af7aea34651359d8b056c6a1af.idx
ipython 29619 root    7r   REG 202,80 54593196 33598181 /mnt/galaxy/galaxy-app/.git/objects/pack/pack-c5d4b5abfd9295af7aea34651359d8b056c6a1af.pack
ipython 29619 root    8r   REG 202,80  4668532 33598182 /mnt/galaxy/galaxy-app/.git/objects/pack/pack-c5d4b5abfd9295af7aea34651359d8b056c6a1af.idx

If there's a way around this, I'd appreciate some advice.
Thanks.

This is on Ubuntu 14.04 with GitPython 1.0.1 and git 1.9.1.

@Byron
Copy link
Member

Byron commented May 12, 2015

Thank you. Which Python version are you using?
In python 3, destructors are usually not called, even if the Repo instance is deleted or goes out of scope.

@Byron Byron added this to the v1.0.2 - Fixes milestone May 12, 2015
@afgane
Copy link
Author

afgane commented May 12, 2015

This is on Python 2.7.6

@Byron
Copy link
Member

Byron commented May 12, 2015

I didn't reproduce it yet, but can imagine this truly is the case.

What happens if you delete your repo instance, e.g. with del repo? This should work on python 2.7 (but I didn't try it yet).
You could also try repo.odb.release() to forcefully free all handles.

If in any of the tests above the handles remain opened, this is indeed a critical and possibly easily reproducible bug.

@afgane
Copy link
Author

afgane commented May 12, 2015

del repo unfortunately does nothing. This was the first thing I tried yesterday.

repo.odb.release() does not exist? The following are the only members odb object shows:

In [31]: r.odb.
r.odb.LooseDBCls                   r.odb.databases                    r.odb.loose_dir                    r.odb.root_path                    r.odb.store
r.odb.PackDBCls                    r.odb.db_path                      r.odb.ostream                      r.odb.set_ostream                  r.odb.stream
r.odb.ReferenceDBCls               r.odb.has_object                   r.odb.packs_dir                    r.odb.sha_iter                     r.odb.update_cache
r.odb.alternates_dir               r.odb.info                         r.odb.partial_to_complete_sha_hex  r.odb.size

I've explored those but no progress.

Thanks for looking into this.

@Byron
Copy link
Member

Byron commented May 13, 2015

Apparently I was wrong about the release() method on the pure-python implementation of the Git database. However, there is a git-command based implementation which uses git cat-file to obtain object information. Whenever such a database is destroyed, the persistent commands will be shut down.

To use it, just instantiate your Repo instance as follows:

import git
r = git.Repo(odbt=git.GitCmdObjectDB)
r.commit().message
# now lsof shows some pack files
del r
# now they are gone

It's a bit sad that there seems to be no way to trigger this kind of resource release in the pure-python implementation, and considering that GitPython is in maintenance mode, I believe this is not going to improve.

Please let me know if the suggested workaround did indeed work for you.
Thanks

@afgane
Copy link
Author

afgane commented May 13, 2015

This worked from the command prompt. I'll try it in the app a bit later.

Thank you.

@Byron
Copy link
Member

Byron commented May 13, 2015

Great to hear ! Feel free to close this issue if it worked in the app as well.

@Byron
Copy link
Member

Byron commented May 14, 2015

You can watch the development stream on youtube.

GitPython #1 [investigate resource leak]

thumb

@afgane
Copy link
Author

afgane commented May 14, 2015

It's working in the larger context as well - thank you again for tracking this down and providing a workaround. (And thanks for capturing the process in the video.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants