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