{"record":{"id":"c8fae7733710d120","repo":"cloudflare/cloudflared","slug":"not-a-tcp-connection","errorCode":null,"errorMessage":"not a tcp connection","messagePattern":"not a tcp connection","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"socks/dialer.go","lineNumber":52,"sourceCode":"}\n\n// ConnDialer is like NetDialer but with an existing TCP dialer already created\ntype ConnDialer struct {\n\tconn net.Conn\n}\n\n// NewConnDialer creates a new dialer with a already created net.conn (TCP expected)\nfunc NewConnDialer(conn net.Conn) Dialer {\n\treturn &ConnDialer{\n\t\tconn: conn,\n\t}\n}\n\n// Dial is a TCP dialer but already created\nfunc (d *ConnDialer) Dial(address string) (io.ReadWriteCloser, *AddrSpec, error) {\n\tlocal, ok := d.conn.LocalAddr().(*net.TCPAddr)\n\tif !ok {\n\t\treturn nil, nil, fmt.Errorf(\"not a tcp connection\")\n\t}\n\n\taddr := AddrSpec{IP: local.IP, Port: local.Port}\n\treturn d.conn, &addr, nil\n}\n","sourceCodeStart":34,"sourceCodeEnd":58,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/socks/dialer.go#L34-L58","documentation":"ConnDialer.Dial inspects the underlying connection's LocalAddr and requires it to be a *net.TCPAddr to construct the AddrSpec reported to the SOCKS client. If the wrapped conn is not a TCP connection (e.g. Unix socket), Dial returns 'not a tcp connection'.","triggerScenarios":"Serving the SOCKS handler over a listener whose accepted connections are not *net.TCPConn, then a client requests a BIND-style reply needing the local address.","commonSituations":"Wrapping the SOCKS handler behind a Unix socket or in-memory pipe; test harnesses using net.Pipe; unusual listener configurations.","solutions":["Serve the SOCKS handler on a TCP listener so conn.LocalAddr() is *net.TCPAddr.","Remove the Unix socket/pipe wrapper for this handler.","If a non-TCP transport is required, supply a dialer that can produce an AddrSpec without a TCP local address.","Check how the conn passed into ConnDialer is created."],"exampleFix":"// before\nln, _ := net.Listen(\"unix\", \"/tmp/socks.sock\")\n// after\nln, _ := net.Listen(\"tcp\", \"127.0.0.1:1080\")","handlingStrategy":"type-guard","validationCode":"if _, ok := conn.LocalAddr().(*net.TCPAddr); !ok { return errors.New(\"socks handler requires TCP connection\") }","typeGuard":"func isTCPConn(conn net.Conn) bool { _, ok := conn.LocalAddr().(*net.TCPAddr); return ok }","tryCatchPattern":"rwc, addr, err := dialer.Dial(address)\nif err != nil {\n    return fmt.Errorf(\"cannot determine local addr: %w\", err)\n}","preventionTips":["Serve SOCKS on a TCP listener only","Avoid wrapping the handler behind Unix sockets/net.Pipe","Use a custom dialer for non-TCP transports","Assert conn type in tests"],"tags":["socks5","tcp","dialer"],"backgroundTag":"unsupported-operation","analyzedSha":"2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f","analyzedAt":"2026-09-06T04:14:33.757Z","contentChangedAt":"2026-09-06T04:14:33.757Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}