Repository: borgbackup/borg

Issue:
crash when failing to acquire lock
If two borg processes try to access the same repository at the same time, I get an Exception. For example if I try `borg list` while an (automated) `borg create` is running, I get the following:

    goerz@mlhpc2:~/bin> borg list  mlhpc1:~/storage/backup/mlhpc2
    Traceback (most recent call last):
    File "borg/archiver.py", line 3482, in main
    File "borg/archiver.py", line 3410, in run
    File "borg/archiver.py", line 106, in wrapper
    File "borg/remote.py", line 566, in __init__
    File "borg/remote.py", line 563, in do_open
    File "borg/remote.py", line 453, in do_rpc
    File "borg/remote.py", line 672, in call
    File "borg/remote.py", line 730, in call_many
    File "borg/remote.py", line 714, in handle_error
    borg.remote.RPCError: {b'exception_args': (b'/data/goerz/backup/mlhpc2/lock.exclusive',), b'exception_short': b'Failed to create/acquire the lock /data/goerz/backup/mlhpc2/lock.exclusive (timeout).', b'exception_class': b'LockTimeout', b'exception_full': (b'Traceback (most recent call last):\n', b'  File "borg/locking.py", line 129, in acquire\n', b"FileExistsError: [Errno 17] File exists: '/data/goerz/backup/mlhpc2/lock.exclusive'\n", b'\nDuring handling of the above exception, another exception occurred:\n\n', b'Traceback (most recent call last):\n', b'  File "borg/remote.py", line 245, in serve\n', b'  File "borg/remote.py", line 351, in open\n', b'  File "borg/repository.py", line 141, in __enter__\n', b'  File "borg/repository.py", line 285, in open\n', b'  File "borg/locking.py", line 320, in acquire\n', b'  File "borg/locking.py", line 113, in __enter__\n', b'  File "borg/locking.py", line 135, in acquire\n', b'borg.locking.LockTimeout: Failed to create/acquire the lock /data/goerz/backup/mlhpc2/lock.exclusive (timeout).\n'), b'i': 2, b'sysinfo': b"Platform: Linux mlhpc1 4.4.0-62-generic #83-Ubuntu SMP Wed Jan 18 14:10:15 UTC 2017 x86_64 x86_64\nLinux: debian stretch/sid \nBorg: 1.1.0b5  Python: CPython 3.5.3\nPID: 16359  CWD: /home/goerz\nsys.argv: ['borg', 'serve', '--umask=077']\nSSH_ORIGINAL_COMMAND: None\n"}

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "borg/__main__.py", line 2, in <module>
    File "borg/archiver.py", line 3496, in main
    File "borg/remote.py", line 469, in get_message
    TypeError: sequence item 0: expected a bytes-like object, int found
    Failed to execute script __main__

Other `borg` sub-commands besides `list` (e.g. another `create`) also crash. I'm using the latest standalone executable of `borg` both on the client and the server.

This is not a huge deal, but you probably want to exit with an error message instead of showing the user the exception traceback. The `TypeError` in `remote.py` might also be an actual bug.



Discussion:
Which version do you mean by latest executable (1.1.0b5 or 1.0.10)?
    goerz@mlhpc2:~> borg --version
    borg 1.1.0b5
that's a bug, not just a locked repo and tracebacky lock message, see 2nd traceback.
Looks like a bug in the processing of the error reported by the server.

Resolving patch:
diff --git a/src/borg/remote.py b/src/borg/remote.py
--- a/src/borg/remote.py
+++ b/src/borg/remote.py
@@ -252,7 +252,7 @@ def serve(self):
                             ex_short = traceback.format_exception_only(e.__class__, e)
                             ex_full = traceback.format_exception(*sys.exc_info())
                             if isinstance(e, Error):
-                                ex_short = e.get_message()
+                                ex_short = [e.get_message()]
                             if isinstance(e, (Repository.DoesNotExist, Repository.AlreadyExists, PathNotAllowed)):
                                 # These exceptions are reconstructed on the client end in RemoteRepository.call_many(),
                                 # and will be handled just like locally raised exceptions. Suppress the remote traceback


Test patch: