borg serve: shutdown server after sending all queued log records

This commit is contained in:
Thomas Waldmann 2023-05-26 13:06:40 +02:00
parent 746cef1cba
commit ac4b5c35da
No known key found for this signature in database
GPG Key ID: 243ACFA951F78E01
1 changed files with 11 additions and 5 deletions

View File

@ -157,6 +157,7 @@ class RepositoryServer: # pragma: no cover
os.set_blocking(stdin_fd, False) os.set_blocking(stdin_fd, False)
os.set_blocking(stdout_fd, True) os.set_blocking(stdout_fd, True)
unpacker = get_limited_unpacker("server") unpacker = get_limited_unpacker("server")
shutdown_serve = False
while True: while True:
# before processing any new RPCs, send out all pending log output # before processing any new RPCs, send out all pending log output
while True: while True:
@ -169,14 +170,19 @@ class RepositoryServer: # pragma: no cover
msg = msgpack.packb({LOG: lr_dict}) msg = msgpack.packb({LOG: lr_dict})
os_write(stdout_fd, msg) os_write(stdout_fd, msg)
if shutdown_serve:
# shutdown wanted! get out of here after sending all log output.
if self.repository is not None:
self.repository.close()
return
# process new RPCs # process new RPCs
r, w, es = select.select([stdin_fd], [], [], 10) r, w, es = select.select([stdin_fd], [], [], 10)
if r: if r:
data = os.read(stdin_fd, BUFSIZE) data = os.read(stdin_fd, BUFSIZE)
if not data: if not data:
if self.repository is not None: shutdown_serve = True
self.repository.close() continue
return
unpacker.feed(data) unpacker.feed(data)
for unpacked in unpacker: for unpacked in unpacker:
if isinstance(unpacked, dict): if isinstance(unpacked, dict):
@ -241,8 +247,8 @@ class RepositoryServer: # pragma: no cover
else: else:
os_write(stdout_fd, msgpack.packb({MSGID: msgid, RESULT: res})) os_write(stdout_fd, msgpack.packb({MSGID: msgid, RESULT: res}))
if es: if es:
self.repository.close() shutdown_serve = True
return continue
def negotiate(self, client_data): def negotiate(self, client_data):
if isinstance(client_data, dict): if isinstance(client_data, dict):