{"record":{"id":"aaa2f10020002717","repo":"netbirdio/netbird","slug":"setenv-w","errorCode":null,"errorMessage":"setenv: %w","messagePattern":"setenv: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/embed/embed.go","lineNumber":175,"sourceCode":"\t\t\treturn nil, fmt.Errorf(\"invalid MTU: %w\", err)\n\t\t}\n\t}\n\n\tif opts.LogOutput != nil {\n\t\tlogrus.SetOutput(opts.LogOutput)\n\t}\n\n\tif opts.LogLevel != \"\" {\n\t\tlevel, err := logrus.ParseLevel(opts.LogLevel)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"parse log level: %w\", err)\n\t\t}\n\t\tlogrus.SetLevel(level)\n\t}\n\n\tif !opts.NoUserspace {\n\t\tif err := os.Setenv(netstack.EnvUseNetstackMode, \"true\"); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"setenv: %w\", err)\n\t\t}\n\t\tif err := os.Setenv(netstack.EnvSkipProxy, \"true\"); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"setenv: %w\", err)\n\t\t}\n\t}\n\n\tif opts.StatePath != \"\" {\n\t\t// TODO: Disable state if path not provided\n\t\tif err := os.Setenv(\"NB_DNS_STATE_FILE\", opts.StatePath); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"setenv: %w\", err)\n\t\t}\n\t}\n\n\tvar err error\n\tvar parsedLabels domain.List\n\tif parsedLabels, err = domain.FromStringList(opts.DNSLabels); err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid dns labels: %w\", err)\n\t}","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/netbirdio/netbird/blob/93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c/client/embed/embed.go#L157-L193","documentation":"Returned by embed.New when os.Setenv for the netstack mode flag (netstack.EnvUseNetstackMode, i.e. the environment variable that switches the agent into netstack mode) fails while enabling userspace networking (opts.NoUserspace == false). os.Setenv on fixed keys virtually never fails; on Unix it can only fail on an invalid key or allocation failure.","triggerScenarios":"Any embed.New call without NoUserspace=true on a platform or process state where setting an environment variable fails (extreme memory pressure, or a Go runtime/OS combination refusing setenv).","commonSituations":"Almost never observed in practice; when it appears it signals the process is out of memory or the runtime is in a degraded state rather than a configuration mistake.","solutions":["Treat it as a fatal environment/runtime problem: check process memory limits and restart the embedding process.","If it recurs on a specific platform, report it upstream; there is no caller-side configuration that fixes a failing os.Setenv."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"client, err := embed.New(opts)\nif err != nil {\n    if strings.HasPrefix(err.Error(), \"setenv\") {\n        // environment/runtime level failure: restart the process rather than retry in-process\n        log.Fatalf(\"runtime cannot set env: %v\", err)\n    }\n    return err\n}","preventionTips":["Monitor process memory; this failure only appears under runtime degradation.","Do not write retry loops around constructor errors that indicate host-level problems."],"tags":["environment","runtime","embed","rare"],"backgroundTag":null,"analyzedSha":"93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c","analyzedAt":"2026-08-16T03:09:19.136Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}