{"record":{"id":"764db02aa13de51e","repo":"ginuerzh/gost","slug":"ssh-wrong-connection-type","errorCode":null,"errorMessage":"ssh: wrong connection type","messagePattern":"ssh: wrong connection type","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ssh.go","lineNumber":84,"sourceCode":"\nfunc (c *sshDirectForwardConnector) Connect(conn net.Conn, raddr string, options ...ConnectOption) (net.Conn, error) {\n\treturn c.ConnectContext(context.Background(), conn, \"tcp\", raddr, options...)\n}\n\nfunc (c *sshDirectForwardConnector) ConnectContext(ctx context.Context, conn net.Conn, network, raddr string, options ...ConnectOption) (net.Conn, error) {\n\tswitch network {\n\tcase \"udp\", \"udp4\", \"udp6\":\n\t\treturn nil, fmt.Errorf(\"%s unsupported\", network)\n\t}\n\n\topts := &ConnectOptions{}\n\tfor _, option := range options {\n\t\toption(opts)\n\t}\n\n\tcc, ok := conn.(*sshNopConn) // TODO: this is an ugly type assertion, need to find a better solution.\n\tif !ok {\n\t\treturn nil, errors.New(\"ssh: wrong connection type\")\n\t}\n\n\ttimeout := opts.Timeout\n\tif timeout <= 0 {\n\t\ttimeout = ConnectTimeout\n\t}\n\n\tcc.session.conn.SetDeadline(time.Now().Add(timeout))\n\tdefer cc.session.conn.SetDeadline(time.Time{})\n\n\tconn, err := cc.session.client.Dial(\"tcp\", raddr)\n\tif err != nil {\n\t\tlog.Logf(\"[ssh-tcp] %s -> %s : %s\", cc.session.addr, raddr, err)\n\t\treturn nil, err\n\t}\n\treturn conn, nil\n}\n","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/ginuerzh/gost/blob/a33fdbf4c98034f4bfeeaea9868909822b9c526d/ssh.go#L66-L102","documentation":"Returned by sshDirectForwardConnector.ConnectContext when the supplied conn is not the expected *sshNopConn wrapper (an ugly but deliberate type check), meaning the connection cannot be used to open a direct-tcpip SSH channel. Additionally, UDP network values are rejected outright with a '%s unsupported' error from the same switch. Both are caller misuse of the connector.","triggerScenarios":"Thrown at ssh.go:84 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass the *sshNopConn produced by the SSH forward transporter into the connector","Use a tcp-family network value; SSH direct forwarding does not carry UDP","For UDP over SSH, use a connector that tunnels UDP inside an SSH channel instead"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a33fdbf4c98034f4bfeeaea9868909822b9c526d","analyzedAt":"2026-09-02T22:15:54.506Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}