Skip to content

OSError: [Errno 2] No such file or directory .lock #4199

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
reaperhulk opened this issue Oct 19, 2018 · 6 comments
Closed

OSError: [Errno 2] No such file or directory .lock #4199

reaperhulk opened this issue Oct 19, 2018 · 6 comments
Labels
plugin: tmpdir related to the tmpdir builtin plugin type: bug problem that needs to be addressed

Comments

@reaperhulk
Copy link
Contributor

This is likely a new pathlib bug and potentially related to #4181. I suspect this may be occurring because the Jenkins builders where this is happening are running up to 5 concurrent pytest instances. Is there any randomness used to prevent tmpname conflicts or could one process be deleting another's lock?

Example of error:

    def create_cleanup_lock(p):
        """crates a lock to prevent premature folder cleanup"""

        lock_path = get_lock_path(p)
        try:
>           fd = os.open(str(lock_path), os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o644)

E           OSError: [Errno 2] No such file or directory: 'c:\\users\\admini~1\\appdata\\local\\temp\\2\\pytest-of-Administrator\\pytest-Administrator\\.lock'
@RonnyPfannschmidt
Copy link
Member

the filename pytest-Administrator is completely unexpected i suspect its an issue with expectations on windows, but due to the incomplete traceback i have absolutely no idea whats happening on your side

@reaperhulk
Copy link
Contributor Author

Oops, sorry. I had the full traceback and failed to paste it:

self = <CallInfo when='setup' exception: [Errno 2] No such file or directory: 'c:\\us...appdata\\local\\temp\\2\\pytest-of-Administrator\\pytest-Administrator\\.lock'>

func = <function <lambda> at 0x2EB170F0>, when = 'setup'
treat_keyboard_interrupt_as_exception = False

    def __init__(self, func, when, treat_keyboard_interrupt_as_exception=False):
        #: context of invocation: one of "setup", "call",
        #: "teardown", "memocollect"

        self.when = when
        self.start = time()
        try:
>           self.result = func()

.tox\py27\lib\site-packages\_pytest\runner.py:206: 

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

.tox\py27\lib\site-packages\_pytest\runner.py:188: in <lambda>
    lambda: ihook(item=item, **kwds),

.tox\py27\lib\site-packages\pluggy\hooks.py:284: in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)

.tox\py27\lib\site-packages\pluggy\manager.py:67: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)

.tox\py27\lib\site-packages\pluggy\manager.py:61: in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,

.tox\py27\lib\site-packages\_pytest\runner.py:109: in pytest_runtest_setup
    item.session._setupstate.prepare(item)

.tox\py27\lib\site-packages\_pytest\runner.py:375: in prepare
    col.setup()

.tox\py27\lib\site-packages\_pytest\python.py:1439: in setup
    fixtures.fillfixtures(self)

.tox\py27\lib\site-packages\_pytest\fixtures.py:294: in fillfixtures
    request._fillfixtures()

.tox\py27\lib\site-packages\_pytest\fixtures.py:467: in _fillfixtures
    item.funcargs[argname] = self.getfixturevalue(argname)

.tox\py27\lib\site-packages\_pytest\fixtures.py:514: in getfixturevalue
    return self._get_active_fixturedef(argname).cached_result[0]

.tox\py27\lib\site-packages\_pytest\fixtures.py:537: in _get_active_fixturedef
    self._compute_fixture_value(fixturedef)

.tox\py27\lib\site-packages\_pytest\fixtures.py:623: in _compute_fixture_value
    fixturedef.execute(request=subrequest)

.tox\py27\lib\site-packages\_pytest\fixtures.py:919: in execute
    return hook.pytest_fixture_setup(fixturedef=self, request=request)

.tox\py27\lib\site-packages\pluggy\hooks.py:284: in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)

.tox\py27\lib\site-packages\pluggy\manager.py:67: in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)

.tox\py27\lib\site-packages\pluggy\manager.py:61: in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,

.tox\py27\lib\site-packages\_pytest\fixtures.py:961: in pytest_fixture_setup
    result = call_fixture_func(fixturefunc, request, kwargs)

.tox\py27\lib\site-packages\_pytest\fixtures.py:820: in call_fixture_func
    res = fixturefunc(**kwargs)

.tox\py27\lib\site-packages\_pytest\tmpdir.py:170: in tmpdir
    return _mk_tmp(request, tmpdir_factory)

.tox\py27\lib\site-packages\_pytest\tmpdir.py:157: in _mk_tmp
    return factory.mktemp(name, numbered=True)

.tox\py27\lib\site-packages\_pytest\tmpdir.py:103: in mktemp
    return py.path.local(self._tmppath_factory.mktemp(basename, numbered).resolve())

.tox\py27\lib\site-packages\_pytest\tmpdir.py:47: in mktemp
    p = make_numbered_dir(root=self.getbasetemp(), prefix=basename)

.tox\py27\lib\site-packages\_pytest\tmpdir.py:66: in getbasetemp
    prefix="pytest-", root=rootdir, keep=3, lock_timeout=LOCK_TIMEOUT

.tox\py27\lib\site-packages\_pytest\pathlib.py:235: in make_numbered_dir_with_cleanup
    consider_lock_dead_if_created_before=consider_lock_dead_if_created_before,

.tox\py27\lib\site-packages\_pytest\pathlib.py:214: in cleanup_numbered_dir
    try_cleanup(path, consider_lock_dead_if_created_before)

.tox\py27\lib\site-packages\_pytest\pathlib.py:196: in try_cleanup
    delete_a_numbered_dir(path)

.tox\py27\lib\site-packages\_pytest\pathlib.py:166: in delete_a_numbered_dir
    create_cleanup_lock(path)

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

p = WindowsPath('c:/users/admini~1/appdata/local/temp/2/pytest-of-Administrator/pytest-Administrator')



    def create_cleanup_lock(p):
        """crates a lock to prevent premature folder cleanup"""
        lock_path = get_lock_path(p)
        try:
>           fd = os.open(str(lock_path), os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o644)

E           OSError: [Errno 2] No such file or directory: 'c:\\users\\admini~1\\appdata\\local\\temp\\2\\pytest-of-Administrator\\pytest-Administrator\\.lock'

.tox\py27\lib\site-packages\_pytest\pathlib.py:127: OSError

@Zac-HD Zac-HD added type: bug problem that needs to be addressed plugin: tmpdir related to the tmpdir builtin plugin labels Oct 19, 2018
@RonnyPfannschmidt
Copy link
Member

thanks, now that makes sense - i believe this is a race condition at folder creation vs cleanup in others - i believe i can set up a way to resolve it cleanly

@nicoddemus
Copy link
Member

@reaperhulk I see you are using Python 2.7, do you have the same problem if you use Python 3 (assuming you also execute your code on that version)?

@reaperhulk
Copy link
Contributor Author

We do execute our test suite against 2.7 and 3.4+ (the cryptography test matrix is unfortunately enormous). However, this bug was resolved in pytest 3.9.3 I believe. We blacklisted 3.9.0, 3.9.1, and 3.9.2 but we haven't had any issue with any more recent release. I apologize for not closing this 😄

@nicoddemus
Copy link
Member

No worries, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: tmpdir related to the tmpdir builtin plugin type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

4 participants