DVC gc issues with shared cache and remote for several repos

Hi,

I’m using DVC for two projects sharing the same remote and cache.

I would like to clean the remote and the cache in order to keep only the data used in the two project workspaces.
But when using the command “gc” with these options: “dvc gc -c -w -p PATH_TO_FIRST_PROJECT PATH_TO_SECOND_PROJECT” I’m getting this error:

"
ERROR: Unable to acquire lock. Most likely another DVC process is running or was terminated abruptly. Check the page https://dvc.org/doc/user-guide/troubleshooting#lock-issue for other possible reasons and to learn how to resolve this.
"

Looking at the indicated webpage I tried to remove the “.dvc/tmp/lock” files in the two projects but the error is still occuring when trying dvc gc.
This error also happens without the cloud “-c” option, just trying to clean the shared cache.
However I’m able to clean the cache with a “dvc gc -w” command in any of the two projects (without the “-p” options, meaning that I’m removing the files tracked in the workspace of the other project).

If someone already had this kind of issue and has a solution to handle this situation, I would be glad to have your feedback on this.
I don’t know if this issue is due to a bad configuration on my side or a bug in DVC…

PS: The output of the “dvc version” command on my system is

DVC version: 2.10.1 (conda)

Platform: Python 3.9.12 on Linux-5.13.0-40-generic-x86_64-with-glibc2.31
Supports:
webhdfs (fsspec = 2022.3.0),
http (aiohttp = 3.8.1, aiohttp-retry = 2.4.6),
https (aiohttp = 3.8.1, aiohttp-retry = 2.4.6),
ssh (sshfs = 2022.3.1)
Cache types: hardlink, symlink
Cache directory: ext4 on /dev/mapper/vgubuntu-root
Caches: local
Remotes: local
Workspace directory: ext4 on /dev/mapper/vgubuntu-root
Repo: dvc, git

Hello @Loic,
Sorry for getting back to you late. Do you still experience this problem?
Would it be possible to post the result for your gc command with -v option?

Hi Paffciu,

I’m still facing this issue.

The result of the “gc -v” command is in my case

user@coltrane:~/Projects/static_project_template$ dvc gc -v -c -w -p /home/user/Projects/static_project_template /home/user/Projects/static_project_template_bis
2022-05-27 13:51:01,831 WARNING: This will remove all cache except items used in the workspace of the current and the following repos:
  - /home/user/Projects/static_project_template
  - /home/user/Projects/static_project_template_bis
Are you sure you want to proceed? [y/n]: y
2022-05-27 13:51:06,396 ERROR: Unable to acquire lock. Most likely another DVC process is running or was terminated abruptly. Check the page <https://dvc.org/doc/user-guide/troubleshooting#lock-issue> for other possible reasons and to learn how to resolve this.
------------------------------------------------------------
Traceback (most recent call last):
  File "/home/user/.dvc-venv/lib/python3.9/site-packages/zc/lockfile/__init__.py", line 59, in _lock_file
    fcntl.flock(file.fileno(), _flags)
BlockingIOError: [Errno 11] Resource temporarily unavailable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/.dvc-venv/lib/python3.9/site-packages/dvc/lock.py", line 112, in _do_lock
    self._lock = zc.lockfile.LockFile(self._lockfile)
  File "/home/user/.dvc-venv/lib/python3.9/site-packages/zc/lockfile/__init__.py", line 117, in __init__
    super(LockFile, self).__init__(path)
  File "/home/user/.dvc-venv/lib/python3.9/site-packages/zc/lockfile/__init__.py", line 90, in __init__
    _lock_file(fp)
  File "/home/user/.dvc-venv/lib/python3.9/site-packages/zc/lockfile/__init__.py", line 61, in _lock_file
    raise LockError("Couldn't lock %r" % file.name)
zc.lockfile.LockError: Couldn't lock '/home/user/Projects/static_project_template/.dvc/tmp/lock'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/.dvc-venv/lib/python3.9/site-packages/dvc/cli/__init__.py", line 89, in main
    ret = cmd.do_run()
  File "/home/user/.dvc-venv/lib/python3.9/site-packages/dvc/cli/command.py", line 22, in do_run
    return self.run()
  File "/home/user/.dvc-venv/lib/python3.9/site-packages/dvc/commands/gc.py", line 51, in run
    self.repo.gc(
  File "/home/user/.dvc-venv/lib/python3.9/site-packages/dvc/repo/__init__.py", line 48, in wrapper
    return f(repo, *args, **kwargs)
  File "/home/user/.dvc-venv/lib/python3.9/site-packages/dvc/repo/gc.py", line 58, in gc
    stack.enter_context(repo.lock)
  File "/home/user/.dvc-venv/lib/python3.9/contextlib.py", line 448, in enter_context
    result = _cm_type.__enter__(cm)
  File "/home/user/.dvc-venv/lib/python3.9/site-packages/dvc/lock.py", line 131, in __enter__
    self.lock()
  File "/home/user/.dvc-venv/lib/python3.9/site-packages/dvc/lock.py", line 120, in lock
    lock_retry()
  File "/home/user/.dvc-venv/lib/python3.9/site-packages/funcy/decorators.py", line 45, in wrapper
    return deco(call, *dargs, **dkwargs)
  File "/home/user/.dvc-venv/lib/python3.9/site-packages/funcy/flow.py", line 127, in retry
    return call()
  File "/home/user/.dvc-venv/lib/python3.9/site-packages/funcy/decorators.py", line 66, in __call__
    return self._func(*self._args, **self._kwargs)
  File "/home/user/.dvc-venv/lib/python3.9/site-packages/dvc/lock.py", line 114, in _do_lock
    raise LockError(FAILED_TO_LOCK_MESSAGE)
dvc.lock.LockError: Unable to acquire lock. Most likely another DVC process is running or was terminated abruptly. Check the page <https://dvc.org/doc/user-guide/troubleshooting#lock-issue> for other possible reasons and to learn how to resolve this.
------------------------------------------------------------

I have two git repo I created to reproduce this issue, “static_project_template” and “static_project_template_bis” that are sharing the same cache and remote.
I’m able to use “dvc gc” in any of these repo, but I’m not able to use it with the “-p” option that is necessary in my case.