1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-26 08:55:40 +03:00

machined: do not send more replies if an error is sent

Previously, if an enumerated machine get an error in fetching
metadata, e.g. missing os-release file, then
list_machine_one_and_maybe_read_metadata() calls sd_varlink_error(),
which returns 1. Hence, the caller vl_method_list() may continue the
loop and call list_machine_one_and_maybe_read_metadata() again to send
information about another machine. But that would fail with -EBUSY, as
we already sent an error message.

Let's check the varlink state before processing machines or machine
images, and skip further operations if an error is sent.

Follow-up for a94fbcaa35.
This commit is contained in:
Yu Watanabe 2024-10-24 19:51:28 +09:00
parent af6cd8c0b5
commit f956b7c936
2 changed files with 21 additions and 0 deletions

View File

@ -421,6 +421,9 @@ static int list_machine_one_and_maybe_read_metadata(sd_varlink *link, Machine *m
assert(link);
assert(m);
if (!sd_varlink_is_processing_method(link))
return 0;
if (should_acquire_metadata(am)) {
_cleanup_free_ struct local_address *addresses = NULL;
@ -596,6 +599,9 @@ static int list_image_one_and_maybe_read_metadata(sd_varlink *link, Image *image
assert(link);
assert(image);
if (!sd_varlink_is_processing_method(link))
return 0;
if (should_acquire_metadata(am) && !image->metadata_valid) {
r = image_read_metadata(image, &image_policy_container);
if (r < 0 && am != ACQUIRE_METADATA_GRACEFUL)

View File

@ -341,7 +341,22 @@ assert_eq "$(echo "$output" | jq --seq .addresses[0].address[0] | tr -d \\036)"
assert_eq "$(echo "$output" | jq --seq .addresses[0].address[1] | tr -d \\036)" '0'
assert_eq "$(echo "$output" | jq --seq .addresses[0].address[2] | tr -d \\036)" '2'
assert_eq "$(echo "$output" | jq --seq .addresses[0].address[3] | tr -d \\036)" '1'
# test for listing multiple machines.
long_running_machine_start
varlinkctl --more call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{}'
varlinkctl --more call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{"acquireMetadata": "no"}'
varlinkctl --more call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{"acquireMetadata": "graceful"}'
# check if machined does not try to send anything after error message
journalctl --sync
TS="$(date '+%H:%M:%S')"
(! varlinkctl --more call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{"acquireMetadata": "yes"}')
journalctl --sync
(! journalctl -u systemd-machined.service --since="$TS" --grep 'Connection busy')
# terminate machines
machinectl terminate "container-without-os-release"
machinectl terminate "long-running"
# wait for the container being stopped, otherwise acquiring image metadata by io.systemd.MachineImage.List may fail in the below.
timeout 30 bash -c 'until [[ "$(systemctl is-active systemd-nspawn@long-running.service)" == "inactive" ]]; do sleep .5; done'
(ip addr show lo | grep -q 192.168.1.100) || ip address add 192.168.1.100/24 dev lo
(! varlinkctl --more call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{"name": ".host"}' | grep 'addresses')