Skip to content

Commit b6e0618

Browse files
committed
fix(preflight): cap COSI read with 2s timeout
Address review feedback from gemini-code-assist on pkg/commands/preflight.go:21,85: the pre-flight COSI read had no timeout, so a slow or unresponsive node could turn an informational best-effort check into a blocker for apply. Wrap the safe.StateGet call with context.WithTimeout (2s) inside cosiVersionReader. The timeout is short enough to stay invisible on a healthy node and long enough to clear any expected roundtrip; on a hung node, the reader returns ok=false and the existing silent-on-error contract takes over. Assisted-By: Claude <noreply@anthropic.com> Signed-off-by: Aleksei Sviridkin <f@lex.la>
1 parent c2659c1 commit b6e0618

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

pkg/commands/preflight.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"fmt"
2020
"io"
2121
"strings"
22+
"time"
2223

2324
"github.com/cockroachdb/errors"
2425
"github.com/cosi-project/runtime/pkg/resource"
@@ -29,6 +30,13 @@ import (
2930
"github.com/siderolabs/talos/pkg/machinery/resources/runtime"
3031
)
3132

33+
// preflightCOSIReadTimeout caps the COSI read latency so a slow or
34+
// unresponsive node cannot turn a best-effort informational check into a
35+
// blocker for `apply`. Two seconds is comfortably above any expected
36+
// roundtrip on a healthy node and short enough to be unnoticeable when the
37+
// read actually fails.
38+
const preflightCOSIReadTimeout = 2 * time.Second
39+
3240
// preflightVersionMismatchHint is the hint attached to the warning when the
3341
// configured talosVersion contract is newer than the version reported by the
3442
// node. It does not name a specific Talos version — the warning line itself
@@ -74,6 +82,9 @@ type versionReader func(ctx context.Context) (version string, ok bool)
7482
// proxy error) is reported as ok=false.
7583
func cosiVersionReader(c *client.Client) versionReader {
7684
return func(ctx context.Context) (string, bool) {
85+
ctx, cancel := context.WithTimeout(ctx, preflightCOSIReadTimeout)
86+
defer cancel()
87+
7788
res, err := safe.StateGet[*runtime.Version](
7889
ctx,
7990
c.COSI,

0 commit comments

Comments
 (0)