{"record":{"id":"9be87f7fbde987b9","repo":"nats-io/nats-server","slug":"could-not-create-consumer-directory-v","errorCode":null,"errorMessage":"could not create consumer directory - %v","messagePattern":"could not create consumer directory - (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/filestore.go","lineNumber":13350,"sourceCode":"\t\treturn nil, ErrStoreClosed\n\t}\n\tif cfg == nil || name == _EMPTY_ {\n\t\treturn nil, fmt.Errorf(\"bad consumer config\")\n\t}\n\n\t// We now allow overrides from a stream being a filestore type and forcing a consumer to be memory store.\n\tif cfg.MemoryStorage {\n\t\t// Create directly here.\n\t\to := &consumerMemStore{ms: fs, name: name, cfg: *cfg}\n\t\tif err := fs.AddConsumer(o); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn o, nil\n\t}\n\n\todir := filepath.Join(fs.fcfg.StoreDir, consumerDir, name)\n\tif err := os.MkdirAll(odir, defaultDirPerms); err != nil {\n\t\treturn nil, fmt.Errorf(\"could not create consumer directory - %v\", err)\n\t}\n\tcsi := &FileConsumerInfo{Name: name, Created: created, ConsumerConfig: *cfg}\n\to := &consumerFileStore{\n\t\tfs:   fs,\n\t\tcfg:  csi,\n\t\tprf:  fs.prf,\n\t\tname: name,\n\t\todir: odir,\n\t\tifn:  filepath.Join(odir, consumerState),\n\t}\n\tkey := sha256.Sum256([]byte(fs.cfg.Name + \"/\" + name))\n\thh, err := highwayhash.NewDigest64(key[:])\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"could not create hash: %v\", err)\n\t}\n\to.hh = hh\n\n\t// Check for encryption.","sourceCodeStart":13332,"sourceCodeEnd":13368,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/filestore.go#L13332-L13368","documentation":"Returned when os.MkdirAll fails to create the consumer's data directory (<StoreDir>/msgs/consumers/<name>) with default directory permissions. Without this directory the file-backed consumer store cannot be initialized, so creation aborts and the error wraps the OS-level cause (%v).","triggerScenarios":"Creating a file-backed consumer where MkdirAll on the consumer directory fails — disk full, permission denied, read-only filesystem, or a file exists at the target path.","commonSituations":"StoreDir on a read-only or full volume; wrong ownership after restoring data as another user; a regular file named like the consumer directory left by a bad restore; SELinux/AppArmor restrictions.","solutions":["Read the wrapped OS error: fix permissions (chown/chmod) or free disk space on StoreDir.","Check that the target path is not occupied by a regular file; remove or rename it.","Ensure the filesystem is writable (not mounted ro) and no security module blocks mkdir.","Verify StoreDir configuration points to the intended writable directory."],"exampleFix":"// before\n$ nats-server with StoreDir /srv/jetstream (read-only mount)\n// after\n$ sudo mount -o remount,rw /srv && sudo chown -R nats:nats /srv/jetstream","handlingStrategy":"validation","validationCode":"// pre-check writability of the store dir\nfi, err := os.Stat(storeDir)\nif err != nil || !fi.IsDir() {\n    return fmt.Errorf(\"StoreDir missing or not a directory: %v\", err)\n}\nif err := syscall.Access(storeDir, os.O_RDWR); err != nil {\n    return fmt.Errorf(\"StoreDir not writable: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"if err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) {\n        log.Printf(\"consumer dir creation failed: %s: %v\", pe.Path, pe.Err)\n    }\n}","preventionTips":["Keep StoreDir on writable, non-full volumes","Match ownership/permissions after data restores","Mount storage rw; check SELinux/AppArmor denials","Ensure no stale files shadow consumer directory paths"],"tags":["jetstream","filestore","consumer","filesystem","permissions"],"backgroundTag":"mkdir-failed","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}