forslund / combo-lock

Apache License 2.0
4 stars 1 forks source link

permission error #21

Closed JarbasAl closed 3 months ago

JarbasAl commented 4 months ago

I am not sure how this happens, but it has been an intermittent issue in OVOS chats

I think it happens when a process running as root creates the lock, then everything else fails with PermissionError: [Errno 13] Permission denied: '/tmp/combo_locks/b3Zvc19jb25maWc=.lock'

removing /tmp/combo_locks directory and restarting the services makes things work again for a while

Jul 14 20:01:10 mycroft systemd[413]: Started Open Voice OS - Core (skills).
Jul 14 20:01:11 mycroft ovos-core[2234]: Traceback (most recent call last):
Jul 14 20:01:11 mycroft ovos-core[2234]:   File "/home/ig/.venvs/ovos/bin/ovos-core", line 5, in <module>
Jul 14 20:01:11 mycroft ovos-core[2234]:     from ovos_core.__main__ import main
Jul 14 20:01:11 mycroft ovos-core[2234]:   File "/home/ig/.venvs/ovos/lib/python3.12/site-packages/ovos_core/__init__.py", line 15, in <module>
Jul 14 20:01:11 mycroft ovos-core[2234]:     from ovos_config.config import Configuration
Jul 14 20:01:11 mycroft ovos-core[2234]:   File "/home/ig/.venvs/ovos/lib/python3.12/site-packages/ovos_config/__init__.py", line 1, in <module>
Jul 14 20:01:11 mycroft ovos-core[2234]:     from ovos_config.config import Configuration, LocalConf, RemoteConf
Jul 14 20:01:11 mycroft ovos-core[2234]:   File "/home/ig/.venvs/ovos/lib/python3.12/site-packages/ovos_config/config.py", line 40, in <module>
Jul 14 20:01:11 mycroft ovos-core[2234]:     class Configuration(dict):
Jul 14 20:01:11 mycroft ovos-core[2234]:   File "/home/ig/.venvs/ovos/lib/python3.12/site-packages/ovos_config/config.py", line 44, in Configuration
Jul 14 20:01:11 mycroft ovos-core[2234]:     default = MycroftDefaultConfig()
Jul 14 20:01:11 mycroft ovos-core[2234]:               ^^^^^^^^^^^^^^^^^^^^^^
Jul 14 20:01:11 mycroft ovos-core[2234]:   File "/home/ig/.venvs/ovos/lib/python3.12/site-packages/ovos_config/models.py", line 180, in __init__
Jul 14 20:01:11 mycroft ovos-core[2234]:     super().__init__(DEFAULT_CONFIG)
Jul 14 20:01:11 mycroft ovos-core[2234]:   File "/home/ig/.venvs/ovos/lib/python3.12/site-packages/ovos_config/models.py", line 153, in __init__
Jul 14 20:01:11 mycroft ovos-core[2234]:     super().__init__(path)
Jul 14 20:01:11 mycroft ovos-core[2234]:   File "/home/ig/.venvs/ovos/lib/python3.12/site-packages/ovos_config/models.py", line 68, in __init__
Jul 14 20:01:11 mycroft ovos-core[2234]:     self.load_local(path)
Jul 14 20:01:11 mycroft ovos-core[2234]:   File "/home/ig/.venvs/ovos/lib/python3.12/site-packages/ovos_config/models.py", line 102, in load_local
Jul 14 20:01:11 mycroft ovos-core[2234]:     with self.__lock:
Jul 14 20:01:11 mycroft ovos-core[2234]:   File "/home/ig/.venvs/ovos/lib/python3.12/site-packages/combo_lock/combo_lock.py", line 92, in __enter__
Jul 14 20:01:11 mycroft ovos-core[2234]:     self.acquire()
Jul 14 20:01:11 mycroft ovos-core[2234]:   File "/home/ig/.venvs/ovos/lib/python3.12/site-packages/combo_lock/combo_lock.py", line 58, in acquire
Jul 14 20:01:11 mycroft ovos-core[2234]:     result = self._acquire(blocking)
Jul 14 20:01:11 mycroft ovos-core[2234]:              ^^^^^^^^^^^^^^^^^^^^^^^
Jul 14 20:01:11 mycroft ovos-core[2234]:   File "/home/ig/.venvs/ovos/lib/python3.12/site-packages/combo_lock/combo_lock.py", line 82, in _acquire
Jul 14 20:01:11 mycroft ovos-core[2234]:     self.plock.acquire()
Jul 14 20:01:11 mycroft ovos-core[2234]:   File "/home/ig/.venvs/ovos/lib/python3.12/site-packages/filelock/_api.py", line 332, in acquire
Jul 14 20:01:11 mycroft ovos-core[2234]:     self._acquire()
Jul 14 20:01:11 mycroft ovos-core[2234]:   File "/home/ig/.venvs/ovos/lib/python3.12/site-packages/filelock/_unix.py", line 42, in _acquire
Jul 14 20:01:11 mycroft ovos-core[2234]:     fd = os.open(self.lock_file, open_flags, self._context.mode)
Jul 14 20:01:11 mycroft ovos-core[2234]:          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jul 14 20:01:11 mycroft ovos-core[2234]: PermissionError: [Errno 13] Permission denied: '/tmp/combo_locks/b3Zvc19jb25maWc=.lock'
Jul 14 20:01:11 mycroft systemd[413]: ovos-core.service: Main process exited, code=exited, status=1/FAILURE
Jul 14 20:01:11 mycroft systemd[413]: ovos-core.service: Failed with result 'exit-code'.
JarbasAl commented 4 months ago

im thinking this line is the cause, when running as root https://github.com/forslund/combo-lock/blob/master/combo_lock/combo_lock.py#L124

forslund commented 4 months ago

That makes sense. Will take a look at it.

forslund commented 4 months ago

I've been looking at it a bit and it seems the filelock aquire/release will turn the files access-rights from globally accessible to only writeable for current user. The directory fix is probably a good idea as well but #22 will only partially remedy the issue as far as I can understand

I'll keep digging some more...

forslund commented 3 months ago

Closed by #22