{"record":{"id":"23d717d487cf51ba","repo":"ginuerzh/gost","slug":"wrong-connection-type","errorCode":null,"errorMessage":"wrong connection type","messagePattern":"wrong connection type","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"http2.go","lineNumber":57,"sourceCode":"\nfunc (c *http2Connector) ConnectContext(ctx context.Context, conn net.Conn, network, address 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\tua := opts.UserAgent\n\tif ua == \"\" {\n\t\tua = DefaultUserAgent\n\t}\n\n\tcc, ok := conn.(*http2ClientConn)\n\tif !ok {\n\t\treturn nil, errors.New(\"wrong connection type\")\n\t}\n\n\tpr, pw := io.Pipe()\n\treq := &http.Request{\n\t\tMethod:        http.MethodConnect,\n\t\tURL:           &url.URL{Scheme: \"https\", Host: cc.addr},\n\t\tHeader:        make(http.Header),\n\t\tProto:         \"HTTP/2.0\",\n\t\tProtoMajor:    2,\n\t\tProtoMinor:    0,\n\t\tBody:          pr,\n\t\tHost:          address,\n\t\tContentLength: -1,\n\t}\n\treq.Header.Set(\"User-Agent\", ua)\n\n\tuser := opts.User\n\tif user == nil {","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/ginuerzh/gost/blob/a33fdbf4c98034f4bfeeaea9868909822b9c526d/http2.go#L39-L75","documentation":"http2 connector's ConnectContext asserts that the passed connection is a *http2ClientConn; if the type assertion fails it returns 'wrong connection type'. This connector only knows how to issue HTTP/2 CONNECT requests over its own client-connection type, so passing any other net.Conn (e.g. a plain TCP conn or an http2Conn) is rejected up front. It is a programming/wiring error, not a network failure.","triggerScenarios":"Calling gost's http2 Connect(ctx, conn, address) with a connection that was not produced by the http2 connector's own Dial (i.e. not a *http2ClientConn) — for example reusing a generic dialer's conn or mixing up http and http2 connector instances.","commonSituations":"Building custom chains where the wrong connector gets paired with a transport's connection; refactors that swap http2 dialer for tcp/relay but keep the http2 connector; passing an http2Conn (server-side stream) into a client Connect call.","solutions":["Ensure the conn passed to Connect comes from the same http2 connector's Dial (a *http2ClientConn)","Fix chain wiring so the http2 node uses the http2 dialer/transport, not a plain TCP dialer","Check node/chain configuration (scheme http2 vs http/tcp) so connector and transport match","Log the concrete type of the conn (%T) at the call site to find where the wrong conn originates"],"exampleFix":"// before\nconn, _ := net.Dial(\"tcp\", addr)\nc, err := h2Connector.Connect(ctx, conn, address) // wrong connection type\n// after\nclientConn, err := h2Connector.Dial(ctx, address, opts) // produces *http2ClientConn\nc, err := h2Connector.Connect(ctx, clientConn, address)","handlingStrategy":"type-guard","validationCode":"// Before calling Connect, ensure the conn came from the same http2 dialer\nif _, ok := conn.(*http2ClientConn); !ok {\n    return fmt.Errorf(\"http2 Connect requires *http2ClientConn, got %T\", conn)\n}","typeGuard":"func isHTTP2ClientConn(c net.Conn) (*http2ClientConn, bool) {\n    cc, ok := c.(*http2ClientConn)\n    return cc, ok\n}","tryCatchPattern":"c, err := connector.Connect(ctx, conn, address)\nif err != nil {\n    if err.Error() == \"wrong connection type\" {\n        return nil, fmt.Errorf(\"wiring bug: conn is %T, expected *http2ClientConn\", conn)\n    }\n    return nil, err\n}","preventionTips":["Always obtain the conn from the same connector family's Dial before Connect","Keep chain configs consistent (http2 node ↔ http2 dialer)","Log %T of connections at chain hand-off points during development"],"tags":["http2","type-assertion","connector","wiring"],"backgroundTag":"wrong-connection-type","analyzedSha":"a33fdbf4c98034f4bfeeaea9868909822b9c526d","analyzedAt":"2026-09-02T22:15:54.506Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}