{"record":{"id":"fe9f6e0580b0d0a8","repo":"juicedata/juicefs","slug":"set-worker-environment-q-s","errorCode":null,"errorMessage":"set worker environment %q: %s","messagePattern":"set worker environment %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/sync.go","lineNumber":523,"sourceCode":"\t\treturn nil, fmt.Errorf(\"load %s key: %w\", mode, err)\n\t}\n\n\tencryptor, err := object.NewDataEncryptor(object.NewKeyEncryptor(privKey), algo)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"create %sor: %w\", mode, err)\n\t}\n\n\treturn object.NewChunkedEncrypted(store, encryptor), nil\n}\n\nfunc loadClusterWorkerConfig(r io.Reader) (string, string, error) {\n\tsrc, dst, env, err := sync.ReadClusterWorkerConfig(r)\n\tif err != nil {\n\t\treturn \"\", \"\", err\n\t}\n\tfor key, value := range env {\n\t\tif err := os.Setenv(key, value); err != nil {\n\t\t\treturn \"\", \"\", fmt.Errorf(\"set worker environment %q: %s\", key, err)\n\t\t}\n\t}\n\treturn src, dst, nil\n}\n\nfunc doSync(c *cli.Context) error {\n\tisWorker := c.String(\"manager\") != \"\"\n\tvar workerSrcURL, workerDstURL string\n\tif isWorker {\n\t\tvar err error\n\t\t// need init before NewConfigFromCli, otherwise the env will not be applied(umask)\n\t\tworkerSrcURL, workerDstURL, err = loadClusterWorkerConfig(os.Stdin)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"load worker config: %s\", err)\n\t\t}\n\t}\n\tsetup(c, 2)\n\tif c.IsSet(\"include\") && !c.IsSet(\"exclude\") {","sourceCodeStart":505,"sourceCodeEnd":541,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/cmd/sync.go#L505-L541","documentation":"loadClusterWorkerConfig reads the worker configuration from the cluster master over stdin via sync.ReadClusterWorkerConfig and then applies the returned environment variables with os.Setenv. This error is wrapped around a failure of os.Setenv for one of those worker-provided keys, typically because the key or value is malformed for the OS (e.g. contains '=' or a NUL byte, or the environment cannot be extended). It surfaces as part of a chained error whose inner text is the original os.Setenv failure.","triggerScenarios":"Running `juicefs sync --worker` (isWorker mode) where the master sends env pairs and one pair fails os.Setenv — most commonly an env key containing '=' or NUL, or an empty key.","commonSituations":"A custom or buggy cluster master feeding malformed environment variables to workers; corrupted IPC stream between master and worker; platform restrictions on env var names in restricted containers.","solutions":["Inspect the inner error text after 'set worker environment' to identify which key failed and why.","Check what the master writes via sync.WriteClusterWorkerConfig — ensure keys are valid env names (no '=', NUL, or empty).","Re-run the sync and capture the master's worker config stream to verify the env payload.","If the master is a custom script, sanitize the env map before sending."],"exampleFix":"// before: master sends raw user input as env key\nenv[userInput] = value\n// after: validate/sanitize the key before sending\nif !isValidEnvKey(userInput) {\n    return fmt.Errorf(\"invalid env key %q\", userInput)\n}\nenv[userInput] = value","handlingStrategy":"validation","validationCode":"for key, value := range env {\n    if key == \"\" || strings.ContainsAny(key, \"=\\x00\") {\n        return fmt.Errorf(\"invalid worker env key %q\", key)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate env keys conform to the platform's env-name rules before sending them to workers","Keep master and worker JuiceFS versions in sync so the IPC config format matches"],"tags":["environment","sync","worker","cli"],"backgroundTag":"invalid-env-var-value","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}