{"record":{"id":"5da500558174994b","repo":"hashicorp/nomad","slug":"failed-to-configure-networking-for-alloc-v","errorCode":null,"errorMessage":"failed to configure networking for alloc: %v","messagePattern":"failed to configure networking for alloc: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/allocrunner/network_hook.go","lineNumber":170,"sourceCode":"\t}\n\n\tif spec != nil {\n\t\tstatus, err := h.networkConfigurator.Setup(context.TODO(), h.alloc, spec, created)\n\t\tif err != nil {\n\t\t\t// if the netns already existed but is invalid, we get\n\t\t\t// ErrCNICheckFailed. We'll try to recover from this one time by\n\t\t\t// recreating the netns from scratch before giving up\n\t\t\tif errors.Is(err, ErrCNICheckFailed) && !checkedOnce {\n\t\t\t\th.logger.Warn(\"network configuration check failed\", \"error\", err)\n\t\t\t\tcheckedOnce = true\n\t\t\t\tdestroyErr := h.manager.DestroyNetwork(h.alloc.ID, spec)\n\t\t\t\tif destroyErr != nil {\n\t\t\t\t\treturn fmt.Errorf(\"%w: destroying network to retry failed: %v\", err, destroyErr)\n\t\t\t\t}\n\t\t\t\tgoto CREATE\n\t\t\t}\n\n\t\t\treturn fmt.Errorf(\"failed to configure networking for alloc: %v\", err)\n\t\t}\n\t\t// A nil status indicates a netns already exists and is configured correctly.\n\t\t// It should have been saved to the local state store.\n\t\tif status == nil {\n\t\t\tstateStatus := h.networkStatus.NetworkStatus()\n\t\t\tif stateStatus == nil {\n\t\t\t\treturn errors.New(\"network already configured but not found in state\")\n\t\t\t}\n\t\t\tstatus = stateStatus\n\t\t}\n\n\t\t// If the driver set the sandbox hostname label, then we will use that\n\t\t// to set the HostsConfig.Hostname. Otherwise, identify the sandbox\n\t\t// container ID which will have been used to set the network namespace\n\t\t// hostname.\n\t\tif hostname, ok := spec.Labels[dockerNetSpecHostnameKey]; ok {\n\t\t\th.spec.HostsConfig = &drivers.HostsConfig{\n\t\t\t\tAddress:  status.Address,","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/allocrunner/network_hook.go#L152-L188","documentation":"The network_hook's Prerun returns this when manager.ConfigureNetwork fails after the one-shot destroy-and-retry (i.e. the retry either wasn't triggered by ErrCNICheckFailed or also failed). The inner error from CNI configuration carries the actual cause; this wrapper just marks networking configuration as the failing stage.","triggerScenarios":"Prerun: ConfigureNetwork(h.alloc.ID, spec, ...) returns a non-nil error and either it is not ErrCNICheckFailed or the single retry (goto CREATE) already happened and failed again.","commonSituations":"CNI ADD failures: port mapping conflicts, bandwidth plugin errors, malformed CNI chaining config, IP allocation failures, tc/netem misconfig, or persistent bridge conflicts that survive the recreate retry.","solutions":["Inspect the wrapped inner error and the nomad client logs for the CNI stderr output.","Validate the CNI network configuration files (JSON validity, plugin names, subnet conflicts).","Fix resource conflicts: free ports used by port mappings, expand the IPAM subnet, or remove conflicting bridges.","Recreate the alloc to get a fresh netns (nomad alloc stop, reschedule).","Restart the client / reconcile network state if stale namespaces persist."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-flight: verify CNI conf validity and free port ranges\nvar conf map[string]interface{}\nif err := json.Unmarshal(cniConf, &conf); err != nil {\n    return fmt.Errorf(\"invalid CNI config: %w\", err)\n}","typeGuard":"func configureFailed(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"failed to configure networking\")\n}","tryCatchPattern":"if err := hook.Prerun(); err != nil && strings.Contains(err.Error(), \"failed to configure networking\") {\n    log.Printf(\"CNI configure failed: %v — check CNI stderr in client logs\", err)\n    // fix config/ports/IPs then reschedule the alloc\n}","preventionTips":["Validate CNI configuration files and chaining before rollout.","Reserve port ranges used by portmap to avoid conflicts.","Size IPAM subnets for the expected alloc density.","Keep CNI plugins and Nomad versions compatible."],"tags":["nomad","network","cni","configuration"],"backgroundTag":"cni-network-configure-failed","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"}