cli: fail at once on an empty unix_socket

It retried until cli.timeout, then said "missing address".
Updates #1926
This commit is contained in:
Kristoffer Dalby committed 2026-11-11 16:42:44 +01:00
1 parent 56a644a28a
commit 2cf95feec6
2 files changed
+18

No files matched your search

+6
View File
@@ -37,6 +37,7 @@ const (
var (
errAPIKeyNotSet = errors.New("HEADSCALE_CLI_API_KEY environment variable needs to be set")
errUnixSocketNotSet = errors.New("unix_socket is empty: set it, or cli.address and cli.api_key for a remote server")
errMissingParameter = errors.New("missing parameters")
errResponseStatus = errors.New("unexpected response status")
)
@@ -250,6 +251,11 @@ func newSocketClient(socketPath string) (*clientv1.ClientWithResponses, error) {
// starts can race its creation; retrying preserves the old gRPC client's
// blocking-dial tolerance rather than failing on a not-yet-present socket.
func dialHeadscaleSocket(ctx context.Context, socketPath string) (net.Conn, error) {
// Retrying cannot help: no socket ever appears at "".
if socketPath == "" {
return nil, errUnixSocketNotSet
}
b := backoff.NewExponentialBackOff()
b.InitialInterval = 50 * time.Millisecond
b.MaxInterval = 1 * time.Second
+12
View File
@@ -1,9 +1,11 @@
package cli
import (
"context"
"os"
"path/filepath"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -99,6 +101,16 @@ func TestCLIAPIKey(t *testing.T) {
}
}
// TestDialEmptySocket: an empty unix_socket fails at once, naming the key,
// instead of retrying until the CLI timeout.
func TestDialEmptySocket(t *testing.T) {
ctx, cancel := context.WithTimeout(t.Context(), time.Second)
defer cancel()
_, err := dialHeadscaleSocket(ctx, "")
require.ErrorIs(t, err, errUnixSocketNotSet)
}
// TestServerConfigDropsCLIKey: the server never holds the CLI's key, which
// may be a file only the CLI can read.
func TestServerConfigDropsCLIKey(t *testing.T) {