Skip to content

Commit 63cfa7e

Browse files
committed
Fix potential deadlocks with talosctl config validation
Since we never flushed the stdout/stderr buffers before checking exit code we could hang indefinitely in case the output was large enough.
1 parent 3710566 commit 63cfa7e

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

app/models/cluster.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,9 @@ def validate_secrets_yaml
6868

6969
cmd = "talosctl gen config -o - --output-types controlplane --with-secrets #{random_tmp_file} test https://host:6443"
7070

71-
Open3.popen3(cmd) do |_stdin, _stdout, stderr, wait_thread|
72-
break if wait_thread.value.success?
73-
74-
errors.add(:secrets, stderr.read)
71+
_stdout, stderr, status = Open3.capture3(cmd)
72+
unless status.success?
73+
errors.add(:secrets, stderr.presence || "talosctl gen config failed")
7574
end
7675
ensure
7776
FileUtils.rm_f(random_tmp_file)

app/models/machine_config.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,18 @@ def generate_config(output_type: server.talos_type)
7171
#{server.cluster.endpoint}
7272
)
7373

74-
config = Open3.popen3(command) do |_stdin, stdout, stderr, wait_thread|
75-
if wait_thread.value.success?
76-
stdout.read
77-
else
78-
output = stderr.read
79-
message = "Failed to generate talos configuration.\nCommand:#{command}\nOutput: #{output}"
80-
raise InvalidConfigError.new(message, output)
81-
end
74+
stdout, stderr, status = Open3.capture3(command)
75+
unless status.success?
76+
message = "Failed to generate talos configuration.\nCommand:#{command}\nOutput: #{stderr}"
77+
raise InvalidConfigError.new(message, stderr)
8278
end
8379

8480
File.delete(secrets_file)
8581
File.delete(patch_file)
8682
File.delete(patch_control_plane_file)
8783
File.delete(patch_worker_file)
8884

89-
talosconfig = YAML.safe_load(config)
85+
talosconfig = YAML.safe_load(stdout)
9086

9187
# Initially talosconfig is generated with an endpoint of 127.0.0.1 and no nodes.
9288
# Hence we add the first control plane IP as both enpoint and node.

0 commit comments

Comments
 (0)