hashicorp/terraform · error

Invalid unix socket path

Error message

Invalid unix socket path %q for %q: %w

What it means

Thrown while resolving a reattach address whose Network is 'unix'. net.ResolveUnixAddr failed to parse the configured String field as a unix socket path.

Solutions

  1. Set addr.String to an absolute, printable filesystem path
  2. Ensure the path contains no NUL bytes or stray control characters
  3. Verify the unix socket file actually exists for the test process
Defensive patterns

Strategy: validation

Validate before calling

// Pre-validate a unix socket path string.
func validUnixPath(s string) bool {
    return s != "" && !strings.ContainsRune(s, 0) // no NUL bytes
}
if c.Addr.Network == "unix" && !validUnixPath(c.Addr.String) {
    return fmt.Errorf("invalid unix socket path %q", c.Addr.String)
}

Type guard

func IsValidUnixPath(s string) bool {
    return s != "" && !strings.ContainsRune(s, 0)
}

Try / catch

providers, err := reattach.DecodeProviders(raw)
if err != nil && strings.Contains(err.Error(), "unix socket") {
    return fmt.Errorf("reattach unix path rejected by the OS: %w", err)
}

Prevention

When it happens

Trigger: c.Addr.Network == "unix" and net.ResolveUnixAddr("unix", c.Addr.String) returned a non-nil error.

Common situations: Path containing a NUL byte or otherwise invalid for the filesystem; empty String field; control characters from a corrupted env var; non-UTF-8 bytes on platforms that reject them.

Related errors


AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11). Data as JSON: /api/errors/3eefd94afc850387. Report an issue: GitHub.

Appendix: source

Thrown at internal/getproviders/reattach/reattach.go:66

			Pid  int
			Test bool
		}
		var m map[string]reattachConfig
		err := json.Unmarshal([]byte(in), &m)
		if err != nil {
			return unmanagedProviders, fmt.Errorf("Invalid format for %s: %w", TF_REATTACH_PROVIDERS, err)
		}
		for p, c := range m {
			a, diags := addrs.ParseProviderSourceString(p)
			if diags.HasErrors() {
				return unmanagedProviders, fmt.Errorf("Error parsing %q as a provider address: %w", a, diags.Err())
			}
			var addr net.Addr
			switch c.Addr.Network {
			case "unix":
				addr, err = net.ResolveUnixAddr("unix", c.Addr.String)
				if err != nil {
					return unmanagedProviders, fmt.Errorf("Invalid unix socket path %q for %q: %w", c.Addr.String, p, err)
				}
			case "tcp":
				addr, err = net.ResolveTCPAddr("tcp", c.Addr.String)
				if err != nil {
					return unmanagedProviders, fmt.Errorf("Invalid TCP address %q for %q: %w", c.Addr.String, p, err)
				}
			default:
				return unmanagedProviders, fmt.Errorf("Unknown address type %q for %q", c.Addr.Network, p)
			}
			unmanagedProviders[a] = &plugin.ReattachConfig{
				Protocol:        plugin.Protocol(c.Protocol),
				ProtocolVersion: c.ProtocolVersion,
				Pid:             c.Pid,
				Test:            c.Test,
				Addr:            addr,
			}
		}
	}

View on GitHub (pinned to d32a084675)