ginuerzh/gost · error

wrong connection type

Error message

wrong connection type

What it means

Returned by socks5MuxBindConnector.ConnectContext when the network argument does not match the connection types the multiplexed bind client can serve — the passed conn must be a *muxBindClientConn and only specific network strings are accepted. It signals a programming error in the caller (wrong network or wrong conn type), not a network failure.

Source

Thrown at socks.go:391

// Socks5MuxBindConnector creates a Connector for SOCKS5 multiplex bind client.
func Socks5MuxBindConnector() Connector {
	return &socks5MuxBindConnector{}
}

func (c *socks5MuxBindConnector) Connect(conn net.Conn, address string, options ...ConnectOption) (net.Conn, error) {
	return c.ConnectContext(context.Background(), conn, "tcp", address, options...)
}

// NOTE: the conn must be *muxBindClientConn.
func (c *socks5MuxBindConnector) ConnectContext(ctx context.Context, conn net.Conn, network, address string, options ...ConnectOption) (net.Conn, error) {
	switch network {
	case "udp", "udp4", "udp6":
		return nil, fmt.Errorf("%s unsupported", network)
	}

	accepter, ok := conn.(Accepter)
	if !ok {
		return nil, errors.New("wrong connection type")
	}

	return accepter.Accept()
}

type socks5MuxBindTransporter struct {
	bindAddr     string
	sessions     map[string]*muxSession // server addr to session mapping
	sessionMutex sync.Mutex
}

// SOCKS5MuxBindTransporter creates a Transporter for SOCKS5 multiplex bind client.
func SOCKS5MuxBindTransporter(bindAddr string) Transporter {
	return &socks5MuxBindTransporter{
		bindAddr: bindAddr,
		sessions: make(map[string]*muxSession),
	}
}

View on GitHub (pinned to a33fdbf4c9)

Solutions

  1. Pass a network value the mux bind connector supports (tcp family) instead of udp
  2. Ensure the conn passed in is the *muxBindClientConn produced by the SOCKS5 mux bind dialer
  3. Route UDP traffic through a UDP-capable connector such as the SOCKS5 UDP tunnel connector
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at socks.go:391 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of ginuerzh/gost@a33fdbf4c9 (2026-09-02). Data as JSON: /api/errors/e32b8a60b51a1da2. Report an issue: GitHub.