{"record":{"id":"662b7ef534396ce5","repo":"hashicorp/nomad","slug":"connect-only-supported-with-exactly-1-network-fou","errorCode":null,"errorMessage":"Connect only supported with exactly 1 network (found %d)","messagePattern":"Connect only supported with exactly 1 network \\(found (.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/agent/consul/connect.go","lineNumber":312,"sourceCode":"\t\treturn\n\t}\n\n\t// common case.\n\tvar tags []string\n\tfor key, value := range defaultTags {\n\t\tif value == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\ttag := key + value\n\t\ttags = append(tags, tag)\n\t}\n\tsort.Strings(tags) // mostly for test stability\n\tcfg[configKey] = tags\n}\n\nfunc connectNetworkInvariants(networks structs.Networks) error {\n\tif n := len(networks); n != 1 {\n\t\treturn fmt.Errorf(\"Connect only supported with exactly 1 network (found %d)\", n)\n\t}\n\treturn nil\n}\n\n// connectPort returns the network and port for the Connect proxy sidecar\n// defined for this service. An error is returned if the network and port\n// cannot be determined.\nfunc connectPort(portLabel string, networks structs.Networks, ports structs.AllocatedPorts) (structs.AllocatedPortMapping, error) {\n\tif err := connectNetworkInvariants(networks); err != nil {\n\t\treturn structs.AllocatedPortMapping{}, err\n\t}\n\tmapping, ok := ports.Get(portLabel)\n\tif !ok {\n\t\tmapping = networks.Port(portLabel)\n\t\tif mapping.Value > 0 {\n\t\t\treturn mapping, nil\n\t\t}\n\t\treturn structs.AllocatedPortMapping{}, fmt.Errorf(\"No port of label %q defined\", portLabel)","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/agent/consul/connect.go#L294-L330","documentation":"connectNetworkInvariants enforces that Connect proxy logic receives exactly one network from the allocation. Connect sidecar registrations map a single task network to a Consul sidecar; with zero or multiple networks the mapping is ambiguous, so an error is thrown.","triggerScenarios":"connectPort or connectExposePathPort invoked with an allocation whose task 'networks' list has a length other than 1 — no network declared, or multiple network stanzas on the task.","commonSituations":"Job files with more than one network block per task (pre-1.x style networking) combined with Connect services, or tasks missing a network stanza while declaring connect-enabled services.","solutions":["Ensure the task declares exactly one network block when using Connect services.","Collapse multiple network stanzas into a single block with multiple ports.","Migrate to the modern 'network { port \"x\" {} }' single-network model required by Connect."],"exampleFix":"// before\nnetwork {\n  mode = \"bridge\"\n  port \"http\" {}\n}\nnetwork {\n  port \"admin\" {}\n}\n// after\nnetwork {\n  mode = \"bridge\"\n  port \"http\" {}\n  port \"admin\" {}\n}","handlingStrategy":"validation","validationCode":"if len(task.Networks) != 1 {\n  return fmt.Errorf(\"task %s: Connect requires exactly 1 network, found %d\", task.Name, len(task.Networks))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use a single network block per task when using Connect.","Merge ports into one network stanza.","Audit legacy multi-network job specs."],"tags":["consul","connect","networking","nomad"],"backgroundTag":"connect-network-count-invariant","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}