{"record":{"id":"e4f8454b0b46e522","repo":"nats-io/nats-server","slug":"could-not-create-consumer-storage-directory-v","errorCode":null,"errorMessage":"could not create consumer storage directory - %v","messagePattern":"could not create consumer storage directory - (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"server/filestore.go","lineNumber":491,"sourceCode":"\n\t// If we error before completion make sure to cleanup.\n\tdefer func() {\n\t\tif err != nil {\n\t\t\tats.Unregister()\n\t\t}\n\t}()\n\n\t// Set flush in place to AsyncFlush which by default is false.\n\tfs.fip = !fcfg.AsyncFlush\n\n\t// Check if this is a new setup.\n\tmdir := filepath.Join(fcfg.StoreDir, msgDir)\n\todir := filepath.Join(fcfg.StoreDir, consumerDir)\n\tif err := os.MkdirAll(mdir, defaultDirPerms); err != nil {\n\t\treturn nil, fmt.Errorf(\"could not create message storage directory - %v\", err)\n\t}\n\tif err := os.MkdirAll(odir, defaultDirPerms); err != nil {\n\t\treturn nil, fmt.Errorf(\"could not create consumer storage directory - %v\", err)\n\t}\n\n\t// Create highway hash for message blocks. Use sha256 of directory as key.\n\tkey := sha256.Sum256([]byte(cfg.Name))\n\tfs.hh, err = highwayhash.NewDigest64(key[:])\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"could not create hash: %v\", err)\n\t}\n\n\tkeyFile := filepath.Join(fs.fcfg.StoreDir, JetStreamMetaFileKey)\n\t_, err = os.Stat(keyFile)\n\t// Either the file should exist (err=nil), or it shouldn't. Any other error is reported.\n\tif err != nil && !os.IsNotExist(err) {\n\t\treturn nil, err\n\t}\n\t// Make sure we do not have an encrypted store underneath of us but no main key.\n\tif fs.prf == nil && err == nil {\n\t\treturn nil, errNoMainKey","sourceCodeStart":473,"sourceCodeEnd":509,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/filestore.go#L473-L509","documentation":"Same setup phase as the message directory: the file store creates the per-stream consumers subdirectory (filepath.Join(StoreDir, consumerDir)); os.MkdirAll failure is wrapped with the OS error. The stream store cannot be created without it.","triggerScenarios":"os.MkdirAll(odir, defaultDirPerms) fails when creating the consumers directory inside StoreDir (server/filestore.go:491).","commonSituations":"Same class of issues as the msgs directory: permissions, read-only mount, disk full, a file colliding with the consumers directory name.","solutions":["Inspect the wrapped %v OS error for the exact cause","Ensure StoreDir is writable by the server process user","Remove any regular file occupying the consumers directory path","Verify disk space and mount is read-write"],"exampleFix":"// before\n// $ ls -ld /data/jetstream => dr-xr-xr-x\n// after\n// $ sudo chmod u+w /data/jetstream && sudo chown nats:nats /data/jetstream\nstore_dir: \"/data/jetstream\"","handlingStrategy":"try-catch","validationCode":"if err := os.MkdirAll(filepath.Join(storeDir, \"obs\"), 0o755); err != nil {\n    return fmt.Errorf(\"consumer dir pre-check failed: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := startStream(); err != nil {\n    if strings.Contains(err.Error(), \"could not create consumer storage directory\") {\n        // fix underlying OS error (perms, space, ro mount), then restart\n    }\n}","preventionTips":["Pre-provision the stream directory tree with correct ownership","Ensure the filesystem is read-write and has free space","Treat the wrapped OS error as authoritative for root cause"],"tags":["jetstream","filesystem","permissions","go"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}