{"record":{"id":"88e90bfcd7cde3e8","repo":"valyala/fasthttp","slug":"only-tcp-tcp4-or-tcp6-is-supported","errorCode":null,"errorMessage":"only tcp, tcp4, or tcp6 is supported ","messagePattern":"only tcp, tcp4, or tcp6 is supported ","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tcplisten/tcplisten.go","lineNumber":185,"sourceCode":"\t\tvar sa6 unix.SockaddrInet6\n\t\tsa6.Port = tcpAddr.Port\n\t\tif tcpAddr.IP == nil {\n\t\t\ttcpAddr.IP = net.IPv4(0, 0, 0, 0)\n\t\t}\n\t\tcopy(sa6.Addr[:], tcpAddr.IP.To16())\n\t\tif tcpAddr.Zone != \"\" {\n\t\t\tifi, err := net.InterfaceByName(tcpAddr.Zone)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, -1, err\n\t\t\t}\n\t\t\tsa6.ZoneId, err = safeIntToUint32(ifi.Index)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, -1, fmt.Errorf(\"unexpected convert net interface index int to uint32: %w\", err)\n\t\t\t}\n\t\t}\n\t\treturn &sa6, unix.AF_INET6, nil\n\tdefault:\n\t\treturn nil, -1, errors.New(\"only tcp, tcp4, or tcp6 is supported \" + network)\n\t}\n}\n\nfunc safeIntToUint32(i int) (uint32, error) {\n\tif i < 0 {\n\t\treturn 0, errors.New(\"value is negative, cannot convert to uint32\")\n\t}\n\tui := uint64(i)\n\tif ui > math.MaxUint32 {\n\t\treturn 0, errors.New(\"value exceeds uint32 max value\")\n\t}\n\treturn uint32(ui), nil\n}\n\nfunc safeIntToUintptr(i int) (uintptr, error) {\n\tif i < 0 {\n\t\treturn 0, errors.New(\"value is negative, cannot convert to uintptr\")\n\t}","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/tcplisten/tcplisten.go#L167-L203","documentation":"getSockaddr validates the network string passed to NewListener and only supports 'tcp', 'tcp4', and 'tcp6'; anything else falls into the default branch and returns this error. The tcplisten package builds raw sockaddr structures, so non-TCP networks (udp, unix, etc.) are simply not implemented. Note the message concatenates the offending network string after a trailing space.","triggerScenarios":"Calling tcplisten.NewListener(network, ...) with a network value other than 'tcp', 'tcp4', or 'tcp6' — e.g. 'udp', 'unix', 'tcp+' or an empty string — from config or a wrapper that forwards the raw net.Listen network argument.","commonSituations":"Reusing a generic listener config that contains 'udp' or 'unix' and passing it to tcplisten; user config typo like 'TCP4' (case-sensitive); assuming tcplisten is a drop-in for net.Listen for all networks.","solutions":["Pass one of 'tcp', 'tcp4', or 'tcp6' to NewListener","Check the exact case: 'tcp4' not 'TCP4'; lowercase the config value before calling","For UDP or Unix sockets use net.Listen/std library instead of tcplisten"],"exampleFix":"// before\nln, err := ctl.NewListener(\"udp\", addr) // error\n// after\nln, err := ctl.NewListener(\"tcp4\", addr)","handlingStrategy":"validation","validationCode":"var validListenerNetworks = map[string]bool{\"tcp\": true, \"tcp4\": true, \"tcp6\": true}\nfunc validateListenerNetwork(n string) error {\n  if !validListenerNetworks[strings.ToLower(n)] {\n    return fmt.Errorf(\"tcplisten supports only tcp/tcp4/tcp6, got %q\", n)\n  }\n  return nil\n}","typeGuard":"func isTCPNetwork(n string) bool {\n  switch strings.ToLower(n) { case \"tcp\", \"tcp4\", \"tcp6\": return true }\n  return false\n}","tryCatchPattern":"ln, err := ctl.NewListener(network, addr)\nif err != nil {\n  if strings.HasPrefix(err.Error(), \"only tcp, tcp4, or tcp6 is supported\") {\n    return fmt.Errorf(\"bad listener network %q: %w\", network, err)\n  }\n  return err\n}","preventionTips":["Whitelist-validate the network string from config before constructing listeners","Lowercase/trim config values — the check is case-sensitive","Use tcplisten only for TCP; route UDP/Unix sockets to net.Listen","Document supported values where the network is configured"],"tags":["network","tcp","listener","validation"],"backgroundTag":"unsupported-network-type","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}