# Buggy code
def __init__(self, root_dir=None):
    from dvc.state import State
    from dvc.lock import Lock
    from dvc.scm import SCM
    from dvc.cache import Cache
    from dvc.data_cloud import DataCloud
    from dvc.repo.metrics import Metrics
    from dvc.scm.tree import WorkingTree
    from dvc.repo.tag import Tag

    root_dir = self.find_root(root_dir)

    self.root_dir = os.path.abspath(os.path.realpath(root_dir))
    self.dvc_dir = os.path.join(self.root_dir, self.DVC_DIR)

    self.config = Config(self.dvc_dir)

    self.scm = SCM(self.root_dir)

    self.tree = WorkingTree(self.root_dir)

    self.lock = Lock(
        os.path.join(self.dvc_dir, "lock"),
        tmp_dir=os.path.join(self.dvc_dir, "tmp"),
    )
    # NOTE: storing state and link_state in the repository itself to avoid
    # any possible state corruption in 'shared cache dir' scenario.
    self.state = State(self, self.config.config)

    core = self.config.config[Config.SECTION_CORE]

    level = core.get(Config.SECTION_CORE_LOGLEVEL)
    if level:
        logger.setLevel(level.upper())

    self.cache = Cache(self)
    self.cloud = DataCloud(self)

    self.metrics = Metrics(self)
    self.tag = Tag(self)

    self._ignore()


# Traceback (flufl.lock._lockfile.NotLockedError)
dvc add -v -R model
DEBUG: Trying to spawn '['c:\\users\\luisfelipe_melo_mora\\appdata\\local\\programs\\python\\python37-32\\python.exe', 'C:\\Users\\luisfelipe_melo_mora\\AppData\\Local\\Programs\\Python\\Python37-32\\Scripts\\dvc', 'daemon', '-q', 'updater']'
DEBUG: Spawned '['c:\\users\\luisfelipe_melo_mora\\appdata\\local\\programs\\python\\python37-32\\python.exe', 'C:\\Users\\luisfelipe_melo_mora\\AppData\\Local\\Programs\\Python\\Python37-32\\Scripts\\dvc', 'daemon', '-q',
'updater']'
ERROR: unexpected error - Already unlocked
------------------------------------------------------------
Traceback (most recent call last):
File "c:\users\luisfelipe_melo_mora\appdata\local\programs\python\python37-32\lib\site-packages\dvc\main.py", line 48, in main
cmd = args.func(args)
File "c:\users\luisfelipe_melo_mora\appdata\local\programs\python\python37-32\lib\site-packages\dvc\command\base.py", line 48, in __init__
updater.check()
File "c:\users\luisfelipe_melo_mora\appdata\local\programs\python\python37-32\lib\site-packages\dvc\updater.py", line 54, in check
self._with_lock(self._check, "checking")
File "c:\users\luisfelipe_melo_mora\appdata\local\programs\python\python37-32\lib\site-packages\dvc\updater.py", line 45, in _with_lock
func()
File "c:\users\luisfelipe_melo_mora\appdata\local\programs\python\python37-32\lib\site-packages\flufl\lock\_lockfile.py", line 338, in __exit__
self.unlock()
File "c:\users\luisfelipe_melo_mora\appdata\local\programs\python\python37-32\lib\site-packages\flufl\lock\_lockfile.py", line 287, in unlock
raise NotLockedError('Already unlocked')
flufl.lock._lockfile.NotLockedError: Already unlocked
------------------------------------------------------------


Having any troubles? Hit us up at https://dvc.org/support, we are always happy to help!

# Fixed code
def __init__(self, root_dir=None):
    from dvc.state import State
    from dvc.lock import make_lock
    from dvc.scm import SCM
    from dvc.cache import Cache
    from dvc.data_cloud import DataCloud
    from dvc.repo.metrics import Metrics
    from dvc.scm.tree import WorkingTree
    from dvc.repo.tag import Tag

    root_dir = self.find_root(root_dir)

    self.root_dir = os.path.abspath(os.path.realpath(root_dir))
    self.dvc_dir = os.path.join(self.root_dir, self.DVC_DIR)

    self.config = Config(self.dvc_dir)

    self.scm = SCM(self.root_dir)

    self.tree = WorkingTree(self.root_dir)

    hardlink_lock = self.config.config["core"].get("hardlink_lock", False)
    self.lock = make_lock(
        os.path.join(self.dvc_dir, "lock"),
        tmp_dir=os.path.join(self.dvc_dir, "tmp"),
        hardlink_lock=hardlink_lock,
        friendly=True,
    )
    # NOTE: storing state and link_state in the repository itself to avoid
    # any possible state corruption in 'shared cache dir' scenario.
    self.state = State(self, self.config.config)

    core = self.config.config[Config.SECTION_CORE]

    level = core.get(Config.SECTION_CORE_LOGLEVEL)
    if level:
        logger.setLevel(level.upper())

    self.cache = Cache(self)
    self.cloud = DataCloud(self)

    self.metrics = Metrics(self)
    self.tag = Tag(self)

    self._ignore()