juanfont/headscale · error

expiring preauthkey: %w

Error message

expiring preauthkey: %w

What it means

Thrown by `headscale preauthkeys expire` when client.ExpirePreAuthKeyWithResponse() fails at the transport level. The --id was read and formatted successfully; the HTTP call to the running server never completed. Non-200 responses go through apiError instead.

Source

Thrown at cmd/headscale/cli/preauthkeys.go:166

}

var expirePreAuthKeyCmd = &cobra.Command{
	Use:     cmdExpire,
	Short:   "Expire a preauthkey",
	Aliases: []string{"revoke", aliasExp, "e"},
	RunE: clientRunE(func(ctx context.Context, client *clientv1.ClientWithResponses, cmd *cobra.Command, args []string) error {
		id, err := preAuthKeyID(cmd)
		if err != nil {
			return err
		}

		idStr := strconv.FormatUint(id, util.Base10)

		resp, err := client.ExpirePreAuthKeyWithResponse(ctx, clientv1.ExpirePreAuthKeyJSONRequestBody{
			Id: &idStr,
		})
		if err != nil {
			return fmt.Errorf("expiring preauthkey: %w", err)
		}

		if resp.StatusCode() != http.StatusOK {
			return apiError(resp.StatusCode(), resp.ApplicationproblemJSONDefault)
		}

		return printOutput(cmd, resp.JSON200, "Key expired")
	}),
}

var deletePreAuthKeyCmd = &cobra.Command{
	Use:     cmdDelete,
	Short:   "Delete a preauthkey",
	Aliases: []string{aliasDel, "rm", "d"},
	RunE: clientRunE(func(ctx context.Context, client *clientv1.ClientWithResponses, cmd *cobra.Command, args []string) error {
		id, err := preAuthKeyID(cmd)
		if err != nil {
			return err

View on GitHub (pinned to 565fd254d0)

Solutions

  1. Confirm the server is up and reachable.
  2. Retry after connectivity is restored; expiry is idempotent.
  3. Verify CLI configuration (address, API key).
  4. If a 404 appears instead (via apiError), re-check the id with `preauthkeys list`.
Defensive patterns

Strategy: retry

Try / catch

resp, err := client.ExpirePreAuthKeyWithResponse(ctx, body)
if err != nil && isTransportError(err) {
    // expiry is idempotent: retry with backoff, then verify via preauthkeys list
}

Prevention

When it happens

Trigger: Server unreachable/down, TLS or DNS failure, connection reset while sending the expire request.

Common situations: Expiring a key during a server restart; network partition between admin box and server; stale server_url.

Related errors


AI-assisted analysis of juanfont/headscale@565fd254d0 (2026-08-15). Data as JSON: /api/errors/e6b047df2da154d0. Report an issue: GitHub.