{"record":{"id":"65f16fa16f79917a","repo":"nats-io/nats-server","slug":"could-not-create-storage-streams-directory-v","errorCode":null,"errorMessage":"could not create storage streams directory - %v","messagePattern":"could not create storage streams directory - (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"server/jetstream.go","lineNumber":1292,"sourceCode":"\ts.Debugf(\"Enabled JetStream for account %q\", a.Name)\n\tif l, ok := limits[_EMPTY_]; ok {\n\t\ts.Debugf(\"  Max Memory:      %s\", friendlyBytes(l.MaxMemory))\n\t\ts.Debugf(\"  Max Storage:     %s\", friendlyBytes(l.MaxStore))\n\t} else {\n\t\tfor t, l := range limits {\n\t\t\ts.Debugf(\"  Tier: %s\", t)\n\t\t\ts.Debugf(\"    Max Memory:      %s\", friendlyBytes(l.MaxMemory))\n\t\t\ts.Debugf(\"    Max Storage:     %s\", friendlyBytes(l.MaxStore))\n\t\t}\n\t}\n\n\t// Clean up any old snapshots that were orphaned while staging.\n\tos.RemoveAll(filepath.Join(js.config.StoreDir, snapStagingDir))\n\n\tsdir := filepath.Join(jsa.storeDir, streamsDir)\n\tif _, err := os.Stat(sdir); os.IsNotExist(err) {\n\t\tif err := os.MkdirAll(sdir, defaultDirPerms); err != nil {\n\t\t\treturn fmt.Errorf(\"could not create storage streams directory - %v\", err)\n\t\t}\n\t\t// Just need to make sure we can write to the directory.\n\t\t// Remove the directory will create later if needed.\n\t\tos.RemoveAll(sdir)\n\t\t// when empty remove parent directory, which may have been created as well\n\t\tos.Remove(jsa.storeDir)\n\t} else {\n\t\t// Restore any state here.\n\t\ts.Debugf(\"Recovering JetStream state for account %q\", a.Name)\n\t}\n\n\t// Remember if we should be encrypted and what cipher we think we should use.\n\tencrypted := s.getOpts().JetStreamKey != _EMPTY_\n\tsc := s.getOpts().JetStreamCipher\n\n\tdoConsumers := func(mset *stream, odir string) {\n\t\tofis, _ := os.ReadDir(odir)\n\t\tif len(ofis) > 0 {","sourceCodeStart":1274,"sourceCodeEnd":1310,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/jetstream.go#L1274-L1310","documentation":"When initializing per-account JetStream storage, the server ensures the <storeDir>/streams directory exists, creating it with defaultDirPerms via os.MkdirAll. If the OS-level mkdir fails (permissions, path conflicts, full disk, not a directory), this error wraps the underlying OS error and aborts account stream storage setup.","triggerScenarios":"Starting a server with jetstream store_dir where os.MkdirAll(jsa.storeDir + '/streams') fails - e.g. permission denied on the store directory, store dir path is a file, read-only filesystem, or disk full.","commonSituations":"store_dir owned by another user (server run as different UID); container volume mounted read-only; leftover file named 'streams' in the store dir; NFS/permission issues after migrating store directories; full disk after large streams.","solutions":["Read the wrapped OS error (%v) to identify the exact filesystem cause.","chown/chmod the jetstream store directory so the server process user can write (defaultDirPerms is typically 0750/0755).","Ensure store_dir path exists, is a directory, and contains no file named 'streams'.","Check disk space and that the filesystem is writable (not read-only mounted).","Fix and restart the server; partially created empty dirs are cleaned up automatically."],"exampleFix":"// before\nstore_dir: \"/nfs/readonly/jetstream\"\n// after (and on host)\nstore_dir: \"/var/lib/nats/jetstream\"\n# mkdir -p /var/lib/nats/jetstream && chown nats:nats /var/lib/nats/jetstream","handlingStrategy":"validation","validationCode":"sd := storeDir\nif fi, err := os.Stat(sd); err != nil || !fi.IsDir() {\n    return fmt.Errorf(\"store_dir %s missing or not a directory: %v\", sd, err)\n}\nprobe := filepath.Join(sd, \".write_probe\")\nif err := os.WriteFile(probe, []byte(\"ok\"), 0600); err != nil {\n    return fmt.Errorf(\"store_dir not writable: %w\", err)\n}\nos.Remove(probe)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["chown/chmod the jetstream store_dir for the server's runtime user before start","Do not mount the store directory read-only in containers","Monitor free disk space on the store volume","Ensure no regular file named 'streams' exists in per-account store dirs","Use `nats-server -t` and a smoke test start after changing store_dir"],"tags":["jetstream","filesystem","permissions","nats-server"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}