Skip to content
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

Exception raised : portalocker.exceptions.LockException: [Errno 9] Bad file descriptor #128

Closed
alcoat opened this issue Dec 3, 2023 · 9 comments

Comments

@alcoat
Copy link

alcoat commented Dec 3, 2023

https://github.com/python-cachier/cachier/blob/5776ee8d63c8a5719ccd3737f0f504bc1a7eb679/cachier/pickle_core.py#L145C67-L145C67

On linux system, the cache file seems to be closed twice. When replacing this part of code with:
#with portalocker.Lock(fpath, mode='rb') as cache_file:
cache_file = portalocker.Lock(fpath, mode='rb')
if cache_file is not None:
try:
self.cache = pickle.load(open(cache_file.filename,"rb"))
except EOFError:
self.cache = {}
the cachier seems to work fine.

@shaypal5
Copy link
Collaborator

shaypal5 commented Dec 4, 2023

I'm sorry, that's not enough information to address the bug.

The package is tested and used on Linux, and this is the first report of such an issue. Also, you didn't explain in anyway how this hampers in any way use of the package.

Also, I would not move from a context manager - which is the correct and more safe way to lock a file - to a simple use of Lock without a much better explanation.

This is issue is marked with wontfix until the issue is shown to be reproducible on any Linux machine, and we get a better explanation of what you believe might be causing the redundant locking, the negative effects of this phenomena and possibly even a better suggestion for a fix (I can't see why portalocker's context manager will cause double locking but their Lock method will not).

@alcoat
Copy link
Author

alcoat commented Dec 4, 2023

Ok here is my environnement : mamba create -n cachier cachier
And the test script:
"""
import cachier
import time
@cachier.cachier()
def _takes_3_seconds(label, value):
time.sleep(3)
return f'{label} {value}'
print(_takes_3_seconds('two', 2))
"""
python cachier_test.py
Traceback (most recent call last):
File "/export/home/coat/cmems/cachier_test.py", line 12, in
print(_takes_3_seconds('two', 2))
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/coat/.conda/envs/cachier/lib/python3.12/site-packages/cachier/core.py", line 263, in func_wrapper
key, entry = core.get_entry(args, kwds)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/coat/.conda/envs/cachier/lib/python3.12/site-packages/cachier/base_core.py", line 42, in get_entry
return self.get_entry_by_key(key)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/coat/.conda/envs/cachier/lib/python3.12/site-packages/cachier/pickle_core.py", line 189, in get_entry_by_key
self._reload_cache()
File "/home/coat/.conda/envs/cachier/lib/python3.12/site-packages/cachier/pickle_core.py", line 124, in _reload_cache
with portalocker.Lock(fpath, mode='rb') as cache_file:
File "/home/coat/.conda/envs/cachier/lib/python3.12/site-packages/portalocker/utils.py", line 163, in enter
return self.acquire()
^^^^^^^^^^^^^^
File "/home/coat/.conda/envs/cachier/lib/python3.12/site-packages/portalocker/utils.py", line 290, in acquire
raise exceptions.LockException(exception)
portalocker.exceptions.LockException: [Errno 9] Bad file descriptor

The system used is Centos 7 or RockyLinux 8 on ext4 filesystem

@alcoat
Copy link
Author

alcoat commented Dec 4, 2023

I am not suggesting a solution with the modification on my first comment : this is really uggly and should not be used. However cachier is not usable for me at this time.

@alcoat
Copy link
Author

alcoat commented Dec 4, 2023

In fact it seems to be the same as #86 with NFS mount. When forcing the cache_dir on the local directory (like /tmp) everything is working

@lordjabez
Copy link
Contributor

@alcoat you said it works if you move cache_dir to /tmp ? What's the type of filesystem you're using when it doesn't work? It wouldn't surprise me if non-local drives such NFS mounts, Samba shares, etc. won't work.

Why is it a non-starter for you to simply use a local disk?

@alcoat
Copy link
Author

alcoat commented Dec 5, 2023

@lordjabez Yes, it works when you move the cache_dir to a local disk. Most of my apps are using NFS shares and do depend on a single computer. After looking for solutions, I found that it is not a problem with cachier but portalocker.
In fact I'm trying to use an app in which cachier is used on a network with share disk spaces

@alcoat alcoat closed this as not planned Won't fix, can't repro, duplicate, stale Dec 5, 2023
@lordjabez
Copy link
Contributor

Perhaps you can create an issue with portalocker and link here? We can update the dependency when it's fixed?

@shaypal5
Copy link
Collaborator

shaypal5 commented Dec 5, 2023

Great, I've responded in the portalocker issue you've created with a link to the first NFS-related issue. Let's see when does this gets solved.

@alcoat
Copy link
Author

alcoat commented Dec 5, 2023 via email

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

No branches or pull requests

3 participants