Repository: borgbackup/borg

Issue:
locking issues on openindiana
```
    openindiana64:                     return self.count
    openindiana64:     
    openindiana64:         def print_locked(msg):
    openindiana64:             with print_lock:
    openindiana64:                 print(msg)
    openindiana64:     
    openindiana64:         def acquire_release_loop(id, timeout, thread_id, lock_owner_counter, exception_counter, print_lock, last_thread=None):
    openindiana64:             print_locked("Thread %2d: Starting acquire_release_loop(id=%s, timeout=%d); lockpath=%s" % (thread_id, id, timeout, lockpath))
    openindiana64:             timer = TimeoutTimer(timeout, -1).start()
    openindiana64:             cycle = 0
    openindiana64:     
    openindiana64:             while not timer.timed_out():
    openindiana64:                 cycle += 1
    openindiana64:                 try:
    openindiana64:                     with ExclusiveLock(lockpath, id=id, timeout=timeout/20, sleep=-1):  # This timeout is only for not exceeding the given timeout by more than 5%. With sleep<0 it's constantly polling anyway.
    openindiana64:                         lock_owner_count = lock_owner_counter.incr()
    openindiana64:                         print_locked("Thread %2d: Acquired the lock. It's my %d. loop cycle. I am the %d. who has the lock concurrently." % (thread_id, cycle, lock_owner_count))
    openindiana64:                         time.sleep(0.005)
    openindiana64:                         lock_owner_count = lock_owner_counter.decr()
    openindiana64:                         print_locked("Thread %2d: Releasing the lock, finishing my %d. loop cycle. Currently, %d colleagues still have the lock." % (thread_id, cycle, lock_owner_count))
    openindiana64:                 except LockTimeout:
    openindiana64:                     print_locked("Thread %2d: Got LockTimeout, finishing my %d. loop cycle." % (thread_id, cycle))
    openindiana64:                 except:
    openindiana64:                     exception_count = exception_counter.incr()
    openindiana64:                     e = format_exc()
    openindiana64:                     print_locked("Thread %2d: Exception thrown, finishing my %d. loop cycle. It's the %d. exception seen until now: %s" % (thread_id, cycle, exception_count, e))
    openindiana64:     
    openindiana64:             print_locked("Thread %2d: Loop timed out--terminating after %d loop cycles." % (thread_id, cycle))
    openindiana64:             if last_thread is not None:  # joining its predecessor, if any
    openindiana64:                 last_thread.join()
    openindiana64:     
    openindiana64:         print('')
    openindiana64:         lock_owner_counter = SynchronizedCounter()
    openindiana64:         exception_counter = SynchronizedCounter()
    openindiana64:         print_lock = ThreadingLock()
    openindiana64:         thread = None
    openindiana64:         for thread_id in range(RACE_TEST_NUM_THREADS):
    openindiana64:             thread = Thread(target=acquire_release_loop, args=(('foo', thread_id, 0), RACE_TEST_DURATION, thread_id, lock_owner_counter, exception_counter, print_lock, thread))
    openindiana64:             thread.start()
    openindiana64:         thread.join()  # joining the last thread
    openindiana64:     
    openindiana64:         assert lock_owner_counter.maxvalue() > 0, 'Never gained the lock? Something went wrong here...'
    openindiana64:         assert lock_owner_counter.maxvalue() <= 1, "Maximal number of concurrent lock holders was %d. So exclusivity is broken." % (lock_owner_counter.maxvalue())
    openindiana64: >       assert exception_counter.value() == 0, "ExclusiveLock threw %d exceptions due to unclean concurrency handling." % (exception_counter.value())
    openindiana64: E       AssertionError: ExclusiveLock threw 3 exceptions due to unclean concurrency handling.
    openindiana64: E       assert 3 == 0
    openindiana64: E         +3
    openindiana64: E         -0
    openindiana64: .tox/py35/lib/python3.5/site-packages/borg/testsuite/locking.py
    openindiana64: :167: AssertionError
    openindiana64: ----------------------------- Captured stdout call -----------------------------
    openindiana64: 
    openindiana64: Thread  0: Starting acquire_release_loop(id=('foo', 0, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread  1: Starting acquire_release_loop(id=('foo', 1, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread  2: Starting acquire_release_loop(id=('foo', 2, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread  0: Acquired the lock. It's my 1. loop cycle. I am the 1. who has the lock concurrently.
    openindiana64: Thread  3: Starting acquire_release_loop(id=('foo', 3, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread  4: Starting acquire_release_loop(id=('foo', 4, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread  5: Starting acquire_release_loop(id=('foo', 5, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread  6: Starting acquire_release_loop(id=('foo', 6, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread  7: Starting acquire_release_loop(id=('foo', 7, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread  8: Starting acquire_release_loop(id=('foo', 8, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread  9: Starting acquire_release_loop(id=('foo', 9, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 10: Starting acquire_release_loop(id=('foo', 10, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 11: Starting acquire_release_loop(id=('foo', 11, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 12: Starting acquire_release_loop(id=('foo', 12, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 13: Starting acquire_release_loop(id=('foo', 13, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 14: Starting acquire_release_loop(id=('foo', 14, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 15: Starting acquire_release_loop(id=('foo', 15, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread  0: Releasing the lock, finishing my 1. loop cycle. Currently, 0 colleagues still have the lock.
    openindiana64: Thread 16: Starting acquire_release_loop(id=('foo', 16, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 17: Starting acquire_release_loop(id=('foo', 17, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 18: Starting acquire_release_loop(id=('foo', 18, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 19: Starting acquire_release_loop(id=('foo', 19, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 20: Starting acquire_release_loop(id=('foo', 20, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 21: Starting acquire_release_loop(id=('foo', 21, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 22: Starting acquire_release_loop(id=('foo', 22, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 23: Starting acquire_release_loop(id=('foo', 23, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 24: Starting acquire_release_loop(id=('foo', 24, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 25: Starting acquire_release_loop(id=('foo', 25, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 26: Starting acquire_release_loop(id=('foo', 26, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 27: Starting acquire_release_loop(id=('foo', 27, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 28: Starting acquire_release_loop(id=('foo', 28, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 29: Starting acquire_release_loop(id=('foo', 29, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 30: Starting acquire_release_loop(id=('foo', 30, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 18: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread 32: Starting acquire_release_loop(id=('foo', 32, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 33: Starting acquire_release_loop(id=('foo', 33, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 34: Starting acquire_release_loop(id=('foo', 34, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 35: Starting acquire_release_loop(id=('foo', 35, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 36: Starting acquire_release_loop(id=('foo', 36, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 37: Starting acquire_release_loop(id=('foo', 37, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 38: Starting acquire_release_loop(id=('foo', 38, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 10: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread 39: Starting acquire_release_loop(id=('foo', 39, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread  3: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread  0: Acquired the lock. It's my 2. loop cycle. I am the 1. who has the lock concurrently.
    openindiana64: Thread  1: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread  4: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread 29: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread 11: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread  6: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread  8: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread  7: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread  2: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread 13: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread 12: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread 15: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread 31: Starting acquire_release_loop(id=('foo', 31, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock
    openindiana64: Thread 16: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread 21: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread 22: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread  9: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread 14: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread 19: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread 24: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread 20: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread 23: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread 27: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread 25: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread 32: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread 26: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread 30: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread 18: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 28: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread  5: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread 17: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread 35: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread  0: Releasing the lock, finishing my 2. loop cycle. Currently, 0 colleagues still have the lock.
    openindiana64: Thread 14: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 10: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 33: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread 36: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread 34: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread  3: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread  1: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread  4: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 29: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 11: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread  8: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread  6: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 12: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread  7: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 13: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread  9: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 31: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread 25: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 16: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 24: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 20: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 26: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 19: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 32: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 23: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 15: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 37: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread 22: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 21: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 35: Acquired the lock. It's my 2. loop cycle. I am the 1. who has the lock concurrently.
    openindiana64: Thread 18: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread 28: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 17: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 39: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread  5: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 34: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 36: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread  3: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread 29: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread  7: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread 12: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread 11: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread 25: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread 13: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread  1: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread  8: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread  6: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread  9: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread 16: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread 20: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread 19: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread 24: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread 32: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread 26: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread 35: Releasing the lock, finishing my 2. loop cycle. Currently, 0 colleagues still have the lock.
    openindiana64: Thread 37: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 21: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread  5: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread  3: Got LockTimeout, finishing my 4. loop cycle.
    openindiana64: Thread 29: Acquired the lock. It's my 4. loop cycle. I am the 1. who has the lock concurrently.
    openindiana64: Thread 38: Got LockTimeout, finishing my 1. loop cycle.
    openindiana64: Thread 25: Got LockTimeout, finishing my 4. loop cycle.
    openindiana64: Thread 11: Got LockTimeout, finishing my 4. loop cycle.
    openindiana64: Thread 34: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread 28: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread 16: Got LockTimeout, finishing my 4. loop cycle.
    openindiana64: Thread 29: Releasing the lock, finishing my 4. loop cycle. Currently, 0 colleagues still have the lock.
    openindiana64: Thread 12: Got LockTimeout, finishing my 4. loop cycle.
    openindiana64: Thread 24: Got LockTimeout, finishing my 4. loop cycle.
    openindiana64: Thread 17: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread 32: Got LockTimeout, finishing my 4. loop cycle.
    openindiana64: Thread 39: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 26: Got LockTimeout, finishing my 4. loop cycle.
    openindiana64: Thread  1: Got LockTimeout, finishing my 4. loop cycle.
    openindiana64: Thread 35: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread 19: Got LockTimeout, finishing my 4. loop cycle.
    openindiana64: Thread  9: Got LockTimeout, finishing my 4. loop cycle.
    openindiana64: Thread 20: Got LockTimeout, finishing my 4. loop cycle.
    openindiana64: Thread 37: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread 21: Got LockTimeout, finishing my 4. loop cycle.
    openindiana64: Thread  3: Got LockTimeout, finishing my 5. loop cycle.
    openindiana64: Thread  5: Got LockTimeout, finishing my 4. loop cycle.
    openindiana64: Thread 34: Acquired the lock. It's my 4. loop cycle. I am the 1. who has the lock concurrently.
    openindiana64: Thread 25: Got LockTimeout, finishing my 5. loop cycle.
    openindiana64: Thread 11: Got LockTimeout, finishing my 5. loop cycle.
    openindiana64: Thread 12: Got LockTimeout, finishing my 5. loop cycle.
    openindiana64: Thread 17: Got LockTimeout, finishing my 4. loop cycle.
    openindiana64: Thread 16: Got LockTimeout, finishing my 5. loop cycle.
    openindiana64: Thread 28: Got LockTimeout, finishing my 4. loop cycle.
    openindiana64: Thread 39: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread 24: Got LockTimeout, finishing my 5. loop cycle.
    openindiana64: Thread 35: Got LockTimeout, finishing my 4. loop cycle.
    openindiana64: Thread  9: Got LockTimeout, finishing my 5. loop cycle.
    openindiana64: Thread 25: Got LockTimeout, finishing my 6. loop cycle.
    openindiana64: Thread 34: Releasing the lock, finishing my 4. loop cycle. Currently, 0 colleagues still have the lock.
    openindiana64: Thread 37: Got LockTimeout, finishing my 4. loop cycle.
    openindiana64: Thread 11: Got LockTimeout, finishing my 6. loop cycle.
    openindiana64: Thread 19: Got LockTimeout, finishing my 5. loop cycle.
    openindiana64: Thread 12: Got LockTimeout, finishing my 6. loop cycle.
    openindiana64: Thread 25: Acquired the lock. It's my 7. loop cycle. I am the 1. who has the lock concurrently.
    openindiana64: Thread 30: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 24: Got LockTimeout, finishing my 6. loop cycle.
    openindiana64: Thread  2: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread  2: Loop timed out--terminating after 2 loop cycles.
    openindiana64: Thread 35: Got LockTimeout, finishing my 5. loop cycle.
    openindiana64: Thread  0: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread  0: Loop timed out--terminating after 3 loop cycles.
    openindiana64: Thread  9: Got LockTimeout, finishing my 6. loop cycle.
    openindiana64: Thread  9: Loop timed out--terminating after 6 loop cycles.
    openindiana64: Thread 31: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 25: Releasing the lock, finishing my 7. loop cycle. Currently, 0 colleagues still have the lock.
    openindiana64: Thread 11: Got LockTimeout, finishing my 7. loop cycle.
    openindiana64: Thread 11: Loop timed out--terminating after 7 loop cycles.
    openindiana64: Thread 15: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread 24: Acquired the lock. It's my 7. loop cycle. I am the 1. who has the lock concurrently.
    openindiana64: Thread 19: Got LockTimeout, finishing my 6. loop cycle.
    openindiana64: Thread 23: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread 33: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 18: Got LockTimeout, finishing my 4. loop cycle.
    openindiana64: Thread  6: Got LockTimeout, finishing my 4. loop cycle.
    openindiana64: Thread  6: Loop timed out--terminating after 4 loop cycles.
    openindiana64: Thread 24: Releasing the lock, finishing my 7. loop cycle. Currently, 0 colleagues still have the lock.
    openindiana64: Thread 39: Got LockTimeout, finishing my 4. loop cycle.
    openindiana64: Thread 16: Got LockTimeout, finishing my 6. loop cycle.
    openindiana64: Thread 16: Loop timed out--terminating after 6 loop cycles.
    openindiana64: Thread 24: Loop timed out--terminating after 7 loop cycles.
    openindiana64: Thread 39: Acquired the lock. It's my 5. loop cycle. I am the 1. who has the lock concurrently.
    openindiana64: Thread 19: Got LockTimeout, finishing my 7. loop cycle.
    openindiana64: Thread  8: Got LockTimeout, finishing my 4. loop cycle.
    openindiana64: Thread  8: Loop timed out--terminating after 4 loop cycles.
    openindiana64: Thread 29: Exception thrown, finishing my 4. loop cycle. It's the 1. exception seen until now: Traceback (most recent call last):
    openindiana64:   File "/export/home/vagrant/borg/borg/.tox/py35/lib/python3.5/site-packages/borg/testsuite/locking.py", line 143, in acquire_release_loop
    openindiana64:     print_locked("Thread %2d: Releasing the lock, finishing my %d. loop cycle. Currently, %d colleagues still have the lock.
    openindiana64: " % (thread_id, cycle, lock_owner_count))
    openindiana64:   File "/export/home/vagrant/borg/borg/.tox/py35/lib/python3.5/site-packages/borg/locking.py", line 118, in __exit__
    openindiana64:     self.release()
    openindiana64:   File "/export/home/vagrant/borg/borg/.tox/py35/lib/python3.5/site-packages/borg/locking.py", line 176, in release
    openindiana64:     raise err
    openindiana64:   File "/export/home/vagrant/borg/borg/.tox/py35/lib/python3.5/site-packages/borg/locking.py", line 172, in release
    openindiana64:     os.rmdir(self.path)
    openindiana64: FileExistsError: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: 
    openindiana64: Thread 36: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread  4: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread  4: Loop timed out--terminating after 3 loop cycles.
    openindiana64: Thread 14: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread 14: Loop timed out--terminating after 3 loop cycles.
    openindiana64: Thread 21: Got LockTimeout, finishing my 5. loop cycle.
    openindiana64: Thread 37: Got LockTimeout, finishing my 5. loop cycle.
    openindiana64: Thread 12: Got LockTimeout, finishing my 7. loop cycle.
    openindiana64: Thread 12: Loop timed out--terminating after 7 loop cycles.
    openindiana64: Thread 35: Got LockTimeout, finishing my 6. loop cycle.
    openindiana64: Thread 39: Releasing the lock, finishing my 5. loop cycle. Currently, 0 colleagues still have the lock.
    openindiana64: Thread  7: Got LockTimeout, finishing my 4. loop cycle.
    openindiana64: Thread  7: Loop timed out--terminating after 4 loop cycles.
    openindiana64: Thread 39: Exception thrown, finishing my 5. loop cycle. It's the 2. exception seen until now: Traceback (most recent call last):
    openindiana64:   File "/export/home/vagrant/borg/borg/.tox/py35/lib/python3.5/site-packages/borg/testsuite/locking.py", line 143, in acquire_release_loop
    openindiana64:     print_locked("Thread %2d: Releasing the lock, finishing my %d. loop cycle. Currently, %d colleagues still have the lock." % (thread_id, cycle, lock_owner_count))
    openindiana64:   File "/export/home/vagrant/borg/borg/.tox/py35/lib/python3.5/site-packages/borg/locking.py", line 118, in __exit__
    openindiana64:     self.release()
    openindiana64:   File "/export/home/vagrant/borg/borg/.tox/py35/lib/python3.5/site-packages/borg/locking.py", line 176, in release
    openindiana64:     raise err
    openindiana64:   File "/export/home/vagrant/borg/borg/.tox/py35/lib/python3.5/site-packages/borg/locking.py", line 172, in release
    openindiana64:     os.rmdir(self.path)
    openindiana64: FileExistsError: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: 
    openindiana64: Thread 33: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread 23: Got LockTimeout, finishing my 4. loop cycle.
    openindiana64: Thread 23: Loop timed out--terminating after 4 loop cycles.
    openindiana64: Thread 10: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread  3: Got LockTimeout, finishing my 6. loop cycle.
    openindiana64: Thread 10: Loop timed out--terminating after 3 loop cycles.
    openindiana64: Thread 39: Got LockTimeout, finishing my 6. loop cycle.
    openindiana64: Thread 39: Loop timed out--terminating after 6 loop cycles.
    openindiana64: Thread 26: Got LockTimeout, finishing my 5. loop cycle.
    openindiana64: Thread 26: Loop timed out--terminating after 5 loop cycles.
    openindiana64: Thread 33: Got LockTimeout, finishing my 4. loop cycle.
    openindiana64: Thread 33: Loop timed out--terminating after 4 loop cycles.
    openindiana64: Thread 21: Loop timed out--terminating after 5 loop cycles.
    openindiana64: Thread 28: Got LockTimeout, finishing my 5. loop cycle.
    openindiana64: Thread 28: Loop timed out--terminating after 5 loop cycles.
    openindiana64: Thread 36: Acquired the lock. It's my 4. loop cycle. I am the 1. who has the lock concurrently.
    openindiana64: Thread 19: Loop timed out--terminating after 7 loop cycles.
    openindiana64: Thread 29: Got LockTimeout, finishing my 5. loop cycle.
    openindiana64: Thread 29: Loop timed out--terminating after 5 loop cycles.
    openindiana64: Thread  3: Loop timed out--terminating after 6 loop cycles.
    openindiana64: Thread 37: Got LockTimeout, finishing my 6. loop cycle.
    openindiana64: Thread 37: Loop timed out--terminating after 6 loop cycles.
    openindiana64: Thread 34: Got LockTimeout, finishing my 5. loop cycle.
    openindiana64: Thread 34: Loop timed out--terminating after 5 loop cycles.
    openindiana64: Thread 15: Got LockTimeout, finishing my 4. loop cycle.
    openindiana64: Thread 15: Loop timed out--terminating after 4 loop cycles.
    openindiana64: Thread 38: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 38: Loop timed out--terminating after 2 loop cycles.
    openindiana64: Thread 13: Got LockTimeout, finishing my 4. loop cycle.
    openindiana64: Thread 13: Loop timed out--terminating after 4 loop cycles.
    openindiana64: Thread 18: Got LockTimeout, finishing my 5. loop cycle.
    openindiana64: Thread 30: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread 30: Loop timed out--terminating after 3 loop cycles.
    openindiana64: Thread 18: Loop timed out--terminating after 5 loop cycles.
    openindiana64: Thread 31: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread 27: Got LockTimeout, finishing my 2. loop cycle.
    openindiana64: Thread 27: Loop timed out--terminating after 2 loop cycles.
    openindiana64: Thread  1: Got LockTimeout, finishing my 5. loop cycle.
    openindiana64: Thread  1: Loop timed out--terminating after 5 loop cycles.
    openindiana64: Thread 22: Got LockTimeout, finishing my 3. loop cycle.
    openindiana64: Thread 22: Loop timed out--terminating after 3 loop cycles.
    openindiana64: Thread 25: Got LockTimeout, finishing my 8. loop cycle.
    openindiana64: Thread 25: Loop timed out--terminating after 8 loop cycles.
    openindiana64: Thread  5: Got LockTimeout, finishing my 5. loop cycle.
    openindiana64: Thread  5: Loop timed out--terminating after 5 loop cycles.
    openindiana64: Thread 36: Releasing the lock, finishing my 4. loop cycle. Currently, 0 colleagues still have the lock.
    openindiana64: Thread 32: Got LockTimeout, finishing my 5. loop cycle.
    openindiana64: Thread 32: Loop timed out--terminating after 5 loop cycles.
    openindiana64: Thread 31: Acquired the lock. It's my 4. loop cycle. I am the 1. who has the lock concurrently.
    openindiana64: Thread 36: Exception thrown, finishing my 4. loop cycle. It's the 3. exception seen until now: Traceback (most recent call last):
    openindiana64:   File "/export/home/vagrant/borg/borg/.tox/py35/lib/python3.5/site-packages/borg/testsuite/locking.py", line 143, in acquire_release_loop
    openindiana64:     print_locked("Thread %2d: Releasing the lock, finishing my %d. loop cycle. Currently, %d colleagues still have the lock." % (thread_id, cycle, lock_owner_count))
    openindiana64:   File "/export/home/vagrant/borg/borg/.tox/py35/lib/python3.5/site-packages/borg/locking.py", line 118, in __exit__
    openindiana64:     self.release()
    openindiana64:   File "/export/home/vagrant/borg/borg/.tox/py35/lib/python3.5/site-packages/borg/locking.py", line 176, in release
    openindiana64:     raise err
    openindiana64:   File "/export/home/vagrant/borg/borg/.tox/py35/lib/python3.5/site-packages/borg/locking.py", line 172, in release
    openindiana64:     os.rmdir(self.path)
    openindiana64: FileExistsError: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: 
    openindiana64: Thread 36: Loop timed out--terminating after 4 loop cycles.
    openindiana64: Thread 20: Got LockTimeout, finishing my 5. loop cycle.
    openindiana64: Thread 20: Loop timed out--terminating after 5 loop cycles.
    openindiana64: Thread 17: Got LockTimeout, finishing my 5. loop cycle.
    openindiana64: Thread 17: Loop timed out--terminating after 5 loop cycles.
    openindiana64: Thread 35: Got LockTimeout, finishing my 7. loop cycle.
    openindiana64: Thread 35: Loop timed out--terminating after 7 loop cycles.
    openindiana64: Thread 31: Releasing the lock, finishing my 4. loop cycle. Currently, 0 colleagues still have the lock.
    openindiana64: Thread 31: Acquired the lock. It's my 5. loop cycle. I am the 1. who has the lock concurrently.
    openindiana64: Thread 31: Releasing the lock, finishing my 5. loop cycle. Currently, 0 colleagues still have the lock.
    openindiana64: Thread 31: Loop timed out--terminating after 5 loop cycles.
    openindiana64: ----------------------------- Captured stderr call -----------------------------
    openindiana64: Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: ------------------------------ Captured log call -------------------------------
    openindiana64: ERROR    borg.locking:logger.py:203 Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: ERROR    borg.locking:logger.py:203 Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: ERROR    borg.locking:logger.py:203 Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: ERROR    borg.locking:logger.py:203 Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: ERROR    borg.locking:logger.py:203 Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: ERROR    borg.locking:logger.py:203 Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: ERROR    borg.locking:logger.py:203 Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: ERROR    borg.locking:logger.py:203 Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: ERROR    borg.locking:logger.py:203 Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: ERROR    borg.locking:logger.py:203 Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: ERROR    borg.locking:logger.py:203 Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: ERROR    borg.locking:logger.py:203 Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: ERROR    borg.locking:logger.py:203 Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: ERROR    borg.locking:logger.py:203 Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: ERROR    borg.locking:logger.py:203 Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-0/popen-gw3/test_race_condition0/lock'
    openindiana64: _ RemoteArchiverTestCase.test_create_content_from_command_with_failed_command __
    openindiana64: [gw2] sunos5 -- Python 3.5.7 /export/home/vagrant/borg/borg/.tox/py35/bin/python
    openindiana64: self = <borg.testsuite.archiver.RemoteArchiverTestCase testMethod=test_create_content_from_command_with_failed_command>
    openindiana64:     def test_create_content_from_command_with_failed_command(self):
    openindiana64:         self.cmd('init', '--encryption=repokey', self.repository_location)
    openindiana64:         output = self.cmd('create', '--content-from-command', self.repository_location + '::test',
    openindiana64:                           '--', 'false', '--arg-passed-to-false', exit_code=2)
    openindiana64: >       assert output.endswith("Command 'false' exited with status 1\n")
    openindiana64: E       AssertionError: assert False
    openindiana64: E        +  where False = <built-in method endswith of str object at 0xfffffd7feaede3f8>("Command 'false' exited with status 1\n")
    openindiana64: E        +    where <built-in method endswith of str object at 0xfffffd7feaede3f8> = "Command 'false' exited with status 255\n".endswith
    openindiana64: .tox/py35/lib/python3.5/site-packages/borg/testsuite/archiver.py
    openindiana64: :1064: AssertionError
```


Discussion:
@alfredo08154711 can you have a look?

platform testing looked fine on linux, freebsd, openbsd, but not on openindiana (python 3.5, 3 test fails).
Here's a full log:
```
(borg-env) vagrant@openindiana:~/borg/borg$ pytest -k test_race_cond
===================================================================== test session starts =====================================================================
platform sunos5 -- Python 3.5.7, pytest-5.4.3, py-1.9.0, pluggy-0.13.1
benchmark: 3.2.3 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
Tests enabled: symlinks, root, hardlinks, modes, atime/mtime
Tests disabled: fuse, BSD flags
rootdir: /export/home/vagrant/borg/borg, inifile: setup.cfg
plugins: xdist-1.33.0, benchmark-3.2.3, cov-2.10.0, forked-1.2.0
collected 1430 items / 1429 deselected / 1 selected                                                                                                           

src/borg/testsuite/locking.py F                                                                                                                         [100%]

========================================================================== FAILURES ===========================================================================
____________________________________________________________ TestExclusiveLock.test_race_condition ____________________________________________________________

self = <borg.testsuite.locking.TestExclusiveLock object at 0xfffffd7feb3e2470>, lockpath = '/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock'

    def test_race_condition(self, lockpath):
    
        class SynchronizedCounter:
    
            def __init__(self, count=0):
                self.lock = ThreadingLock()
                self.count = count
                self.maxcount = count
    
            def value(self):
                with self.lock:
                    return self.count
    
            def maxvalue(self):
                with self.lock:
                    return self.maxcount
    
            def incr(self):
                with self.lock:
                    self.count += 1
                    if self.count > self.maxcount:
                        self.maxcount = self.count
                    return self.count
    
            def decr(self):
                with self.lock:
                    self.count -= 1
                    return self.count
    
        def print_locked(msg):
            with print_lock:
                print(msg)
    
        def acquire_release_loop(id, timeout, thread_id, lock_owner_counter, exception_counter, print_lock, last_thread=None):
            print_locked("Thread %2d: Starting acquire_release_loop(id=%s, timeout=%d); lockpath=%s" % (thread_id, id, timeout, lockpath))
            timer = TimeoutTimer(timeout, -1).start()
            cycle = 0
    
            while not timer.timed_out():
                cycle += 1
                try:
                    with ExclusiveLock(lockpath, id=id, timeout=timeout/20, sleep=-1):  # This timeout is only for not exceeding the given timeout by more than 5%. With sleep<0 it's constantly polling anyway.
                        lock_owner_count = lock_owner_counter.incr()
                        print_locked("Thread %2d: Acquired the lock. It's my %d. loop cycle. I am the %d. who has the lock concurrently." % (thread_id, cycle, lock_owner_count))
                        time.sleep(0.005)
                        lock_owner_count = lock_owner_counter.decr()
                        print_locked("Thread %2d: Releasing the lock, finishing my %d. loop cycle. Currently, %d colleagues still have the lock." % (thread_id, cycle, lock_owner_count))
                except LockTimeout:
                    print_locked("Thread %2d: Got LockTimeout, finishing my %d. loop cycle." % (thread_id, cycle))
                except:
                    exception_count = exception_counter.incr()
                    e = format_exc()
                    print_locked("Thread %2d: Exception thrown, finishing my %d. loop cycle. It's the %d. exception seen until now: %s" % (thread_id, cycle, exception_count, e))
    
            print_locked("Thread %2d: Loop timed out--terminating after %d loop cycles." % (thread_id, cycle))
            if last_thread is not None:  # joining its predecessor, if any
                last_thread.join()
    
        print('')
        lock_owner_counter = SynchronizedCounter()
        exception_counter = SynchronizedCounter()
        print_lock = ThreadingLock()
        thread = None
        for thread_id in range(RACE_TEST_NUM_THREADS):
            thread = Thread(target=acquire_release_loop, args=(('foo', thread_id, 0), RACE_TEST_DURATION, thread_id, lock_owner_counter, exception_counter, print_lock, thread))
            thread.start()
        thread.join()  # joining the last thread
    
        assert lock_owner_counter.maxvalue() > 0, 'Never gained the lock? Something went wrong here...'
        assert lock_owner_counter.maxvalue() <= 1, "Maximal number of concurrent lock holders was %d. So exclusivity is broken." % (lock_owner_counter.maxvalue())
>       assert exception_counter.value() == 0, "ExclusiveLock threw %d exceptions due to unclean concurrency handling." % (exception_counter.value())
E       AssertionError: ExclusiveLock threw 2 exceptions due to unclean concurrency handling.
E       assert 2 == 0
E        +  where 2 = <bound method TestExclusiveLock.test_race_condition.<locals>.SynchronizedCounter.value of <borg.testsuite.locking.TestExclusiveLock.test_race_condition.<locals>.SynchronizedCounter object at 0xfffffd7feb3e2860>>()
E        +    where <bound method TestExclusiveLock.test_race_condition.<locals>.SynchronizedCounter.value of <borg.testsuite.locking.TestExclusiveLock.test_race_condition.<locals>.SynchronizedCounter object at 0xfffffd7feb3e2860>> = <borg.testsuite.locking.TestExclusiveLock.test_race_condition.<locals>.SynchronizedCounter object at 0xfffffd7feb3e2860>.value

src/borg/testsuite/locking.py:167: AssertionError
-------------------------------------------------------------------- Captured stdout call ---------------------------------------------------------------------

Thread  0: Starting acquire_release_loop(id=('foo', 0, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread  1: Starting acquire_release_loop(id=('foo', 1, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread  2: Starting acquire_release_loop(id=('foo', 2, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread  3: Starting acquire_release_loop(id=('foo', 3, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread  4: Starting acquire_release_loop(id=('foo', 4, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread  5: Starting acquire_release_loop(id=('foo', 5, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread  6: Starting acquire_release_loop(id=('foo', 6, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread  7: Starting acquire_release_loop(id=('foo', 7, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread  8: Starting acquire_release_loop(id=('foo', 8, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread  1: Acquired the lock. It's my 1. loop cycle. I am the 1. who has the lock concurrently.
Thread  9: Starting acquire_release_loop(id=('foo', 9, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 10: Starting acquire_release_loop(id=('foo', 10, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 11: Starting acquire_release_loop(id=('foo', 11, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 12: Starting acquire_release_loop(id=('foo', 12, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 13: Starting acquire_release_loop(id=('foo', 13, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 14: Starting acquire_release_loop(id=('foo', 14, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 15: Starting acquire_release_loop(id=('foo', 15, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 16: Starting acquire_release_loop(id=('foo', 16, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 17: Starting acquire_release_loop(id=('foo', 17, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 18: Starting acquire_release_loop(id=('foo', 18, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 19: Starting acquire_release_loop(id=('foo', 19, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 20: Starting acquire_release_loop(id=('foo', 20, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 21: Starting acquire_release_loop(id=('foo', 21, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 22: Starting acquire_release_loop(id=('foo', 22, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 23: Starting acquire_release_loop(id=('foo', 23, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 24: Starting acquire_release_loop(id=('foo', 24, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 25: Starting acquire_release_loop(id=('foo', 25, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 26: Starting acquire_release_loop(id=('foo', 26, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 27: Starting acquire_release_loop(id=('foo', 27, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 28: Starting acquire_release_loop(id=('foo', 28, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 29: Starting acquire_release_loop(id=('foo', 29, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 30: Starting acquire_release_loop(id=('foo', 30, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 31: Starting acquire_release_loop(id=('foo', 31, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 32: Starting acquire_release_loop(id=('foo', 32, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 33: Starting acquire_release_loop(id=('foo', 33, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 34: Starting acquire_release_loop(id=('foo', 34, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 35: Starting acquire_release_loop(id=('foo', 35, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 36: Starting acquire_release_loop(id=('foo', 36, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 37: Starting acquire_release_loop(id=('foo', 37, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 38: Starting acquire_release_loop(id=('foo', 38, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread 39: Starting acquire_release_loop(id=('foo', 39, 0), timeout=0); lockpath=/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock
Thread  1: Releasing the lock, finishing my 1. loop cycle. Currently, 0 colleagues still have the lock.
Thread  0: Got LockTimeout, finishing my 1. loop cycle.
Thread  3: Got LockTimeout, finishing my 1. loop cycle.
Thread  2: Got LockTimeout, finishing my 1. loop cycle.
Thread  8: Got LockTimeout, finishing my 1. loop cycle.
Thread 13: Got LockTimeout, finishing my 1. loop cycle.
Thread  7: Got LockTimeout, finishing my 1. loop cycle.
Thread  5: Got LockTimeout, finishing my 1. loop cycle.
Thread  9: Got LockTimeout, finishing my 1. loop cycle.
Thread 16: Got LockTimeout, finishing my 1. loop cycle.
Thread 15: Got LockTimeout, finishing my 1. loop cycle.
Thread 11: Got LockTimeout, finishing my 1. loop cycle.
Thread  4: Got LockTimeout, finishing my 1. loop cycle.
Thread 14: Got LockTimeout, finishing my 1. loop cycle.
Thread  6: Got LockTimeout, finishing my 1. loop cycle.
Thread 17: Got LockTimeout, finishing my 1. loop cycle.
Thread 10: Got LockTimeout, finishing my 1. loop cycle.
Thread 12: Got LockTimeout, finishing my 1. loop cycle.
Thread 18: Got LockTimeout, finishing my 1. loop cycle.
Thread 19: Got LockTimeout, finishing my 1. loop cycle.
Thread 20: Got LockTimeout, finishing my 1. loop cycle.
Thread 22: Got LockTimeout, finishing my 1. loop cycle.
Thread 26: Got LockTimeout, finishing my 1. loop cycle.
Thread 25: Got LockTimeout, finishing my 1. loop cycle.
Thread 28: Got LockTimeout, finishing my 1. loop cycle.
Thread 24: Got LockTimeout, finishing my 1. loop cycle.
Thread 21: Got LockTimeout, finishing my 1. loop cycle.
Thread 29: Got LockTimeout, finishing my 1. loop cycle.
Thread 23: Got LockTimeout, finishing my 1. loop cycle.
Thread 30: Got LockTimeout, finishing my 1. loop cycle.
Thread  1: Acquired the lock. It's my 2. loop cycle. I am the 1. who has the lock concurrently.
Thread 31: Got LockTimeout, finishing my 1. loop cycle.
Thread 32: Got LockTimeout, finishing my 1. loop cycle.
Thread 27: Got LockTimeout, finishing my 1. loop cycle.
Thread 34: Got LockTimeout, finishing my 1. loop cycle.
Thread 38: Got LockTimeout, finishing my 1. loop cycle.
Thread 35: Got LockTimeout, finishing my 1. loop cycle.
Thread 37: Got LockTimeout, finishing my 1. loop cycle.
Thread 33: Got LockTimeout, finishing my 1. loop cycle.
Thread 13: Got LockTimeout, finishing my 2. loop cycle.
Thread  5: Got LockTimeout, finishing my 2. loop cycle.
Thread  8: Got LockTimeout, finishing my 2. loop cycle.
Thread  3: Got LockTimeout, finishing my 2. loop cycle.
Thread 36: Got LockTimeout, finishing my 1. loop cycle.
Thread  9: Got LockTimeout, finishing my 2. loop cycle.
Thread 11: Got LockTimeout, finishing my 2. loop cycle.
Thread  4: Got LockTimeout, finishing my 2. loop cycle.
Thread  2: Got LockTimeout, finishing my 2. loop cycle.
Thread  7: Got LockTimeout, finishing my 2. loop cycle.
Thread 39: Got LockTimeout, finishing my 1. loop cycle.
Thread 16: Got LockTimeout, finishing my 2. loop cycle.
Thread 10: Got LockTimeout, finishing my 2. loop cycle.
Thread  0: Got LockTimeout, finishing my 2. loop cycle.
Thread 19: Got LockTimeout, finishing my 2. loop cycle.
Thread  1: Releasing the lock, finishing my 2. loop cycle. Currently, 0 colleagues still have the lock.
Thread  6: Got LockTimeout, finishing my 2. loop cycle.
Thread 28: Got LockTimeout, finishing my 2. loop cycle.
Thread 20: Got LockTimeout, finishing my 2. loop cycle.
Thread 18: Got LockTimeout, finishing my 2. loop cycle.
Thread 22: Got LockTimeout, finishing my 2. loop cycle.
Thread 14: Got LockTimeout, finishing my 2. loop cycle.
Thread 12: Got LockTimeout, finishing my 2. loop cycle.
Thread 17: Got LockTimeout, finishing my 2. loop cycle.
Thread 25: Got LockTimeout, finishing my 2. loop cycle.
Thread 15: Got LockTimeout, finishing my 2. loop cycle.
Thread 26: Got LockTimeout, finishing my 2. loop cycle.
Thread 32: Got LockTimeout, finishing my 2. loop cycle.
Thread 24: Got LockTimeout, finishing my 2. loop cycle.
Thread 35: Got LockTimeout, finishing my 2. loop cycle.
Thread 29: Got LockTimeout, finishing my 2. loop cycle.
Thread 34: Got LockTimeout, finishing my 2. loop cycle.
Thread 33: Got LockTimeout, finishing my 2. loop cycle.
Thread 27: Got LockTimeout, finishing my 2. loop cycle.
Thread 21: Got LockTimeout, finishing my 2. loop cycle.
Thread 23: Got LockTimeout, finishing my 2. loop cycle.
Thread 30: Got LockTimeout, finishing my 2. loop cycle.
Thread 37: Got LockTimeout, finishing my 2. loop cycle.
Thread 31: Got LockTimeout, finishing my 2. loop cycle.
Thread 38: Got LockTimeout, finishing my 2. loop cycle.
Thread  3: Got LockTimeout, finishing my 3. loop cycle.
Thread  8: Got LockTimeout, finishing my 3. loop cycle.
Thread 13: Got LockTimeout, finishing my 3. loop cycle.
Thread 11: Acquired the lock. It's my 3. loop cycle. I am the 1. who has the lock concurrently.
Thread  9: Got LockTimeout, finishing my 3. loop cycle.
Thread 36: Got LockTimeout, finishing my 2. loop cycle.
Thread  5: Got LockTimeout, finishing my 3. loop cycle.
Thread 16: Got LockTimeout, finishing my 3. loop cycle.
Thread  7: Got LockTimeout, finishing my 3. loop cycle.
Thread 39: Got LockTimeout, finishing my 2. loop cycle.
Thread  2: Got LockTimeout, finishing my 3. loop cycle.
Thread  4: Got LockTimeout, finishing my 3. loop cycle.
Thread  1: Got LockTimeout, finishing my 3. loop cycle.
Thread 20: Got LockTimeout, finishing my 3. loop cycle.
Thread 18: Got LockTimeout, finishing my 3. loop cycle.
Thread 28: Got LockTimeout, finishing my 3. loop cycle.
Thread  0: Got LockTimeout, finishing my 3. loop cycle.
Thread  6: Got LockTimeout, finishing my 3. loop cycle.
Thread 19: Got LockTimeout, finishing my 3. loop cycle.
Thread 10: Got LockTimeout, finishing my 3. loop cycle.
Thread 14: Got LockTimeout, finishing my 3. loop cycle.
Thread 22: Got LockTimeout, finishing my 3. loop cycle.
Thread 12: Got LockTimeout, finishing my 3. loop cycle.
Thread 17: Got LockTimeout, finishing my 3. loop cycle.
Thread 25: Got LockTimeout, finishing my 3. loop cycle.
Thread 29: Got LockTimeout, finishing my 3. loop cycle.
Thread 21: Got LockTimeout, finishing my 3. loop cycle.
Thread 32: Got LockTimeout, finishing my 3. loop cycle.
Thread 35: Got LockTimeout, finishing my 3. loop cycle.
Thread 26: Got LockTimeout, finishing my 3. loop cycle.
Thread 11: Releasing the lock, finishing my 3. loop cycle. Currently, 0 colleagues still have the lock.
Thread 15: Got LockTimeout, finishing my 3. loop cycle.
Thread 33: Got LockTimeout, finishing my 3. loop cycle.
Thread 30: Got LockTimeout, finishing my 3. loop cycle.
Thread 27: Got LockTimeout, finishing my 3. loop cycle.
Thread 34: Got LockTimeout, finishing my 3. loop cycle.
Thread 24: Got LockTimeout, finishing my 3. loop cycle.
Thread 37: Got LockTimeout, finishing my 3. loop cycle.
Thread 38: Got LockTimeout, finishing my 3. loop cycle.
Thread  8: Got LockTimeout, finishing my 4. loop cycle.
Thread  9: Got LockTimeout, finishing my 4. loop cycle.
Thread 23: Got LockTimeout, finishing my 3. loop cycle.
Thread 13: Got LockTimeout, finishing my 4. loop cycle.
Thread  3: Got LockTimeout, finishing my 4. loop cycle.
Thread 36: Got LockTimeout, finishing my 3. loop cycle.
Thread 31: Got LockTimeout, finishing my 3. loop cycle.
Thread 39: Got LockTimeout, finishing my 3. loop cycle.
Thread  2: Got LockTimeout, finishing my 4. loop cycle.
Thread  5: Got LockTimeout, finishing my 4. loop cycle.
Thread  7: Got LockTimeout, finishing my 4. loop cycle.
Thread 16: Got LockTimeout, finishing my 4. loop cycle.
Thread 20: Got LockTimeout, finishing my 4. loop cycle.
Thread 17: Acquired the lock. It's my 4. loop cycle. I am the 1. who has the lock concurrently.
Thread  4: Got LockTimeout, finishing my 4. loop cycle.
Thread  1: Got LockTimeout, finishing my 4. loop cycle.
Thread  6: Got LockTimeout, finishing my 4. loop cycle.
Thread 28: Got LockTimeout, finishing my 4. loop cycle.
Thread 11: Exception thrown, finishing my 3. loop cycle. It's the 1. exception seen until now: Traceback (most recent call last):
  File "/export/home/vagrant/borg/borg/src/borg/testsuite/locking.py", line 143, in acquire_release_loop
    print_locked("Thread %2d: Releasing the lock, finishing my %d. loop cycle. Currently, %d colleagues still have the lock." % (thread_id, cycle, lock_owner_count))
  File "/export/home/vagrant/borg/borg/src/borg/locking.py", line 118, in __exit__
    self.release()
  File "/export/home/vagrant/borg/borg/src/borg/locking.py", line 176, in release
    raise err
  File "/export/home/vagrant/borg/borg/src/borg/locking.py", line 172, in release
    os.rmdir(self.path)
FileExistsError: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock'

Thread 19: Got LockTimeout, finishing my 4. loop cycle.
Thread 25: Got LockTimeout, finishing my 4. loop cycle.
Thread 18: Got LockTimeout, finishing my 4. loop cycle.
Thread 21: Got LockTimeout, finishing my 4. loop cycle.
Thread 10: Got LockTimeout, finishing my 4. loop cycle.
Thread 12: Got LockTimeout, finishing my 4. loop cycle.
Thread 14: Got LockTimeout, finishing my 4. loop cycle.
Thread 22: Got LockTimeout, finishing my 4. loop cycle.
Thread 27: Got LockTimeout, finishing my 4. loop cycle.
Thread 30: Got LockTimeout, finishing my 4. loop cycle.
Thread 29: Got LockTimeout, finishing my 4. loop cycle.
Thread 37: Got LockTimeout, finishing my 4. loop cycle.
Thread  0: Got LockTimeout, finishing my 4. loop cycle.
Thread 35: Got LockTimeout, finishing my 4. loop cycle.
Thread 34: Got LockTimeout, finishing my 4. loop cycle.
Thread 15: Got LockTimeout, finishing my 4. loop cycle.
Thread 24: Got LockTimeout, finishing my 4. loop cycle.
Thread 32: Got LockTimeout, finishing my 4. loop cycle.
Thread  8: Got LockTimeout, finishing my 5. loop cycle.
Thread 33: Got LockTimeout, finishing my 4. loop cycle.
Thread 38: Got LockTimeout, finishing my 4. loop cycle.
Thread 26: Got LockTimeout, finishing my 4. loop cycle.
Thread  9: Got LockTimeout, finishing my 5. loop cycle.
Thread 23: Got LockTimeout, finishing my 4. loop cycle.
Thread 17: Releasing the lock, finishing my 4. loop cycle. Currently, 0 colleagues still have the lock.
Thread  3: Got LockTimeout, finishing my 5. loop cycle.
Thread  5: Got LockTimeout, finishing my 5. loop cycle.
Thread  7: Got LockTimeout, finishing my 5. loop cycle.
Thread 31: Got LockTimeout, finishing my 4. loop cycle.
Thread 36: Got LockTimeout, finishing my 4. loop cycle.
Thread 39: Got LockTimeout, finishing my 4. loop cycle.
Thread 25: Got LockTimeout, finishing my 5. loop cycle.
Thread 13: Got LockTimeout, finishing my 5. loop cycle.
Thread  2: Got LockTimeout, finishing my 5. loop cycle.
Thread  1: Got LockTimeout, finishing my 5. loop cycle.
Thread  1: Loop timed out--terminating after 5 loop cycles.
Thread 18: Got LockTimeout, finishing my 5. loop cycle.
Thread 11: Got LockTimeout, finishing my 4. loop cycle.
Thread 19: Got LockTimeout, finishing my 5. loop cycle.
Thread 21: Got LockTimeout, finishing my 5. loop cycle.
Thread 20: Got LockTimeout, finishing my 5. loop cycle.
Thread  4: Got LockTimeout, finishing my 5. loop cycle.
Thread  4: Loop timed out--terminating after 5 loop cycles.
Thread  6: Got LockTimeout, finishing my 5. loop cycle.
Thread  6: Loop timed out--terminating after 5 loop cycles.
Thread 16: Got LockTimeout, finishing my 5. loop cycle.
Thread 37: Got LockTimeout, finishing my 5. loop cycle.
Thread 12: Got LockTimeout, finishing my 5. loop cycle.
Thread 10: Got LockTimeout, finishing my 5. loop cycle.
Thread 10: Loop timed out--terminating after 5 loop cycles.
Thread 14: Acquired the lock. It's my 5. loop cycle. I am the 1. who has the lock concurrently.
Thread 34: Got LockTimeout, finishing my 5. loop cycle.
Thread 29: Got LockTimeout, finishing my 5. loop cycle.
Thread 32: Got LockTimeout, finishing my 5. loop cycle.
Thread  0: Got LockTimeout, finishing my 5. loop cycle.
Thread  0: Loop timed out--terminating after 5 loop cycles.
Thread 24: Got LockTimeout, finishing my 5. loop cycle.
Thread 15: Got LockTimeout, finishing my 5. loop cycle.
Thread 15: Loop timed out--terminating after 5 loop cycles.
Thread 23: Got LockTimeout, finishing my 5. loop cycle.
Thread 33: Got LockTimeout, finishing my 5. loop cycle.
Thread 38: Got LockTimeout, finishing my 5. loop cycle.
Thread 26: Got LockTimeout, finishing my 5. loop cycle.
Thread  7: Got LockTimeout, finishing my 6. loop cycle.
Thread  7: Loop timed out--terminating after 6 loop cycles.
Thread 28: Got LockTimeout, finishing my 5. loop cycle.
Thread 17: Got LockTimeout, finishing my 5. loop cycle.
Thread 17: Loop timed out--terminating after 5 loop cycles.
Thread 31: Got LockTimeout, finishing my 5. loop cycle.
Thread 36: Got LockTimeout, finishing my 5. loop cycle.
Thread 39: Got LockTimeout, finishing my 5. loop cycle.
Thread 13: Got LockTimeout, finishing my 6. loop cycle.
Thread 13: Loop timed out--terminating after 6 loop cycles.
Thread 22: Got LockTimeout, finishing my 5. loop cycle.
Thread 22: Loop timed out--terminating after 5 loop cycles.
Thread 12: Loop timed out--terminating after 5 loop cycles.
Thread 27: Got LockTimeout, finishing my 5. loop cycle.
Thread 27: Loop timed out--terminating after 5 loop cycles.
Thread 35: Got LockTimeout, finishing my 5. loop cycle.
Thread  8: Got LockTimeout, finishing my 6. loop cycle.
Thread  8: Loop timed out--terminating after 6 loop cycles.
Thread  2: Got LockTimeout, finishing my 6. loop cycle.
Thread  2: Loop timed out--terminating after 6 loop cycles.
Thread 21: Got LockTimeout, finishing my 6. loop cycle.
Thread 21: Loop timed out--terminating after 6 loop cycles.
Thread 14: Releasing the lock, finishing my 5. loop cycle. Currently, 0 colleagues still have the lock.
Thread  3: Got LockTimeout, finishing my 6. loop cycle.
Thread  3: Loop timed out--terminating after 6 loop cycles.
Thread 16: Got LockTimeout, finishing my 6. loop cycle.
Thread 30: Got LockTimeout, finishing my 5. loop cycle.
Thread 30: Loop timed out--terminating after 5 loop cycles.
Thread 25: Got LockTimeout, finishing my 6. loop cycle.
Thread 25: Loop timed out--terminating after 6 loop cycles.
Thread 24: Got LockTimeout, finishing my 6. loop cycle.
Thread 24: Loop timed out--terminating after 6 loop cycles.
Thread 29: Got LockTimeout, finishing my 6. loop cycle.
Thread 29: Loop timed out--terminating after 6 loop cycles.
Thread 33: Got LockTimeout, finishing my 6. loop cycle.
Thread 33: Loop timed out--terminating after 6 loop cycles.
Thread 32: Got LockTimeout, finishing my 6. loop cycle.
Thread 32: Loop timed out--terminating after 6 loop cycles.
Thread 23: Got LockTimeout, finishing my 6. loop cycle.
Thread 23: Loop timed out--terminating after 6 loop cycles.
Thread 38: Got LockTimeout, finishing my 6. loop cycle.
Thread 26: Got LockTimeout, finishing my 6. loop cycle.
Thread 26: Loop timed out--terminating after 6 loop cycles.
Thread 11: Got LockTimeout, finishing my 5. loop cycle.
Thread 11: Loop timed out--terminating after 5 loop cycles.
Thread 39: Acquired the lock. It's my 6. loop cycle. I am the 1. who has the lock concurrently.
Thread 19: Got LockTimeout, finishing my 6. loop cycle.
Thread 19: Loop timed out--terminating after 6 loop cycles.
Thread 16: Loop timed out--terminating after 6 loop cycles.
Thread 20: Got LockTimeout, finishing my 6. loop cycle.
Thread 20: Loop timed out--terminating after 6 loop cycles.
Thread 34: Got LockTimeout, finishing my 6. loop cycle.
Thread 37: Got LockTimeout, finishing my 6. loop cycle.
Thread 18: Got LockTimeout, finishing my 6. loop cycle.
Thread  5: Got LockTimeout, finishing my 6. loop cycle.
Thread  5: Loop timed out--terminating after 6 loop cycles.
Thread 31: Got LockTimeout, finishing my 6. loop cycle.
Thread 31: Loop timed out--terminating after 6 loop cycles.
Thread 14: Exception thrown, finishing my 5. loop cycle. It's the 2. exception seen until now: Traceback (most recent call last):
  File "/export/home/vagrant/borg/borg/src/borg/testsuite/locking.py", line 143, in acquire_release_loop
    print_locked("Thread %2d: Releasing the lock, finishing my %d. loop cycle. Currently, %d colleagues still have the lock." % (thread_id, cycle, lock_owner_count))
  File "/export/home/vagrant/borg/borg/src/borg/locking.py", line 118, in __exit__
    self.release()
  File "/export/home/vagrant/borg/borg/src/borg/locking.py", line 176, in release
    raise err
  File "/export/home/vagrant/borg/borg/src/borg/locking.py", line 172, in release
    os.rmdir(self.path)
FileExistsError: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock'

Thread 14: Loop timed out--terminating after 5 loop cycles.
Thread 34: Loop timed out--terminating after 6 loop cycles.
Thread 18: Loop timed out--terminating after 6 loop cycles.
Thread 28: Got LockTimeout, finishing my 6. loop cycle.
Thread 28: Loop timed out--terminating after 6 loop cycles.
Thread  9: Got LockTimeout, finishing my 6. loop cycle.
Thread  9: Loop timed out--terminating after 6 loop cycles.
Thread 36: Got LockTimeout, finishing my 6. loop cycle.
Thread 36: Loop timed out--terminating after 6 loop cycles.
Thread 39: Releasing the lock, finishing my 6. loop cycle. Currently, 0 colleagues still have the lock.
Thread 39: Loop timed out--terminating after 6 loop cycles.
Thread 35: Got LockTimeout, finishing my 6. loop cycle.
Thread 35: Loop timed out--terminating after 6 loop cycles.
Thread 37: Acquired the lock. It's my 7. loop cycle. I am the 1. who has the lock concurrently.
Thread 38: Got LockTimeout, finishing my 7. loop cycle.
Thread 38: Loop timed out--terminating after 7 loop cycles.
Thread 37: Releasing the lock, finishing my 7. loop cycle. Currently, 0 colleagues still have the lock.
Thread 37: Loop timed out--terminating after 7 loop cycles.
-------------------------------------------------------------------- Captured stderr call ---------------------------------------------------------------------
Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock'
Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock'
Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock'
Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock'
---------------------------------------------------------------------- Captured log call ----------------------------------------------------------------------
ERROR    borg.locking:logger.py:203 Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock'
ERROR    borg.locking:logger.py:203 Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock'
ERROR    borg.locking:logger.py:203 Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock'
ERROR    borg.locking:logger.py:203 Failed to remove lock dir: [Errno 17] File exists: '/tmp/pytest-of-vagrant/pytest-2/test_race_condition0/lock'
=================================================================== short test summary info ===================================================================
FAILED src/borg/testsuite/locking.py::TestExclusiveLock::test_race_condition - AssertionError: ExclusiveLock threw 2 exceptions due to unclean concurrency h...
============================================================= 1 failed, 1429 deselected in 2.82s ==============================================================
```
that makes it work - looks like openindiana gives EEXISTS instead of ENOTEMPTY:
```
diff --git a/src/borg/locking.py b/src/borg/locking.py
index 34f5281f..3eea3d9d 100644
--- a/src/borg/locking.py
+++ b/src/borg/locking.py
@@ -171,7 +171,7 @@ def release(self):
         try:
             os.rmdir(self.path)
         except OSError as err:
-            if err.errno not in (errno.ENOTEMPTY, errno.ENOENT):
+            if err.errno not in (errno.ENOTEMPTY, errno.EEXIST, errno.ENOENT):
                 # EACCES or EIO or ... = we cannot operate anyway, so re-throw
                 raise err
             # else:
```


Resolving patch:
diff --git a/src/borg/locking.py b/src/borg/locking.py
--- a/src/borg/locking.py
+++ b/src/borg/locking.py
@@ -171,7 +171,7 @@ def release(self):
         try:
             os.rmdir(self.path)
         except OSError as err:
-            if err.errno not in (errno.ENOTEMPTY, errno.ENOENT):
+            if err.errno not in (errno.ENOTEMPTY, errno.EEXIST, errno.ENOENT):
                 # EACCES or EIO or ... = we cannot operate anyway, so re-throw
                 raise err
             # else:
@@ -224,7 +224,7 @@ def kill_stale_lock(self):
         try:
             os.rmdir(self.path)
         except OSError as err:
-            if err.errno == errno.ENOTEMPTY or err.errno == errno.ENOENT:
+            if err.errno in (errno.ENOTEMPTY, errno.EEXIST, errno.ENOENT):
                 # Directory is not empty or doesn't exist any more = we lost the race to somebody else--which is ok.
                 return False
             # EACCES or EIO or ... = we cannot operate anyway


Test patch: