From 43a20b052e1d0ac4881625832610702621486713 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Fri, 19 Jan 2024 18:38:07 +0100 Subject: [PATCH] add ConnectionBrokenWithHint for BrokenPipeErrors and similar, see #7016 no traceback, but error message and specific exit code. --- docs/internals/frontends.rst | 2 ++ src/borg/remote.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/internals/frontends.rst b/docs/internals/frontends.rst index 786667fd..08e2f4f4 100644 --- a/docs/internals/frontends.rst +++ b/docs/internals/frontends.rst @@ -699,6 +699,8 @@ Errors UnexpectedRPCDataFormatFromServer rc: 86 traceback: no Got unexpected RPC data format from server: {} + ConnectionBrokenWithHint rc: 87 traceback: no + Connection to remote host is broken. {} IntegrityError rc: 90 traceback: yes Data integrity error: {} diff --git a/src/borg/remote.py b/src/borg/remote.py index 37d74150..924b36ad 100644 --- a/src/borg/remote.py +++ b/src/borg/remote.py @@ -112,6 +112,12 @@ class UnexpectedRPCDataFormatFromServer(Error): super().__init__(data) +class ConnectionBrokenWithHint(Error): + """Connection to remote host is broken. {}""" + + exit_mcode = 87 + + # Protocol compatibility: # In general the server is responsible for rejecting too old clients and the client it responsible for rejecting # too old servers. This ensures that the knowledge what is compatible is always held by the newer component. @@ -428,7 +434,10 @@ class SleepingBandwidthLimiter: self.ratelimit_last = time.monotonic() if len(to_send) > self.ratelimit_quota: to_send = to_send[: self.ratelimit_quota] - written = os.write(fd, to_send) + try: + written = os.write(fd, to_send) + except BrokenPipeError: + raise ConnectionBrokenWithHint("Broken Pipe") from None if self.ratelimit: self.ratelimit_quota -= written return written