tailscale/tailscale · error

magicsock: Rebind IPv4 failed: %w

Error message

magicsock: Rebind IPv4 failed: %w

What it means

rebind: after tolerating an IPv6 bind failure, the required IPv4 socket bind also failed. magicsock considers IPv4 binding mandatory, so rebind returns this wrapped error; a later link-change event will attempt rebind again.

Source

Thrown at wgengine/magicsock/magicsock.go:3799

	}
	return fmt.Errorf("failed to bind any ports (tried %v)", ports)
}

type currentPortFate uint8

const (
	keepCurrentPort = currentPortFate(0)
	dropCurrentPort = currentPortFate(1)
)

// rebind closes and re-binds the UDP sockets.
// We consider it successful if we manage to bind the IPv4 socket.
func (c *Conn) rebind(curPortFate currentPortFate) error {
	if err := c.bindSocket(&c.pconn6, "udp6", curPortFate); err != nil {
		c.logf("magicsock: Rebind ignoring IPv6 bind failure: %v", err)
	}
	if err := c.bindSocket(&c.pconn4, "udp4", curPortFate); err != nil {
		return fmt.Errorf("magicsock: Rebind IPv4 failed: %w", err)
	}
	if c.portMapper != nil {
		c.portMapper.SetLocalPort(c.LocalPort())
	}
	c.UpdatePMTUD()
	return nil
}

// Rebind closes and re-binds the UDP sockets and resets the DERP connection.
// It should be followed by a call to ReSTUN.
func (c *Conn) Rebind() {
	metricRebindCalls.Add(1)
	if err := c.rebind(keepCurrentPort); err != nil {
		c.logf("%v", err)
		return
	}

	var ifIPs []netip.Prefix

View on GitHub (pinned to 5201273aec)

Solutions

  1. Check the wrapped error for the bind failure cause (address in use, permission denied, or interface down).
  2. Ensure the local IPv4 address is still assigned to an interface; a network change may have removed it.
  3. Let magicsock retry after the network change settles; restart tailscaled if it does not recover.
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at wgengine/magicsock/magicsock.go:3821 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of tailscale/tailscale@5201273aec (2026-08-18). Data as JSON: /api/errors/0e6d7badc07e3def. Report an issue: GitHub.