{"record":{"id":"07b1d6518d7d30ce","repo":"nats-io/nats-server","slug":"could-not-create-snapshots-directory-v-07b1d6","errorCode":null,"errorMessage":"could not create snapshots directory - %v","messagePattern":"could not create snapshots directory - (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/stream.go","lineNumber":9325,"sourceCode":"\n\ts, jsa, err := a.checkForJetStream()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tjs := jsa.js\n\tif js == nil {\n\t\treturn nil, NewJSNotEnabledForAccountError()\n\t}\n\n\tcfg, apiErr := s.checkStreamCfg(ncfg, a, false)\n\tif apiErr != nil {\n\t\treturn nil, apiErr\n\t}\n\n\tsd := filepath.Join(jsa.storeDir, snapsDir)\n\tif _, err := os.Stat(sd); os.IsNotExist(err) {\n\t\tif err := os.MkdirAll(sd, defaultDirPerms); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"could not create snapshots directory - %v\", err)\n\t\t}\n\t}\n\tsdir, err := os.MkdirTemp(sd, \"snap-\")\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif _, err := os.Stat(sdir); os.IsNotExist(err) {\n\t\tif err := os.MkdirAll(sdir, defaultDirPerms); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"could not create snapshots directory - %v\", err)\n\t\t}\n\t}\n\tdefer os.RemoveAll(sdir)\n\n\tlogAndReturnError := func() error {\n\t\ta.mu.RLock()\n\t\terr := fmt.Errorf(\"unexpected content (account=%s)\", a.Name)\n\t\tif a.srv != nil {\n\t\t\ta.srv.Errorf(\"Stream restore failed due to %v\", err)","sourceCodeStart":9307,"sourceCodeEnd":9343,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/stream.go#L9307-L9343","documentation":"Before taking a stream snapshot (StreamSnapshot API), the server ensures the snapshots directory under the JetStore dir (snapsDir) exists; if os.MkdirAll fails, the snapshot is aborted with this wrapped OS error. It reflects a filesystem-level problem, not a user config problem.","triggerScenarios":"Calling the stream snapshot API ($JS.API.STREAM.SNAPSHOT.<stream>) when <store_dir>/snaps cannot be created - permissions, read-only filesystem, disk full, or store dir removed out from under a running server.","commonSituations":"JetStream store directory on a read-only mount, running the server as a user without write permission to the store dir, container with a read-only rootfs, or a custom -sd path with wrong ownership.","solutions":["Check and fix permissions/ownership on the JetStream store directory so the server user can create subdirectories.","Verify the filesystem is writable and not full (df / mount).","Restart the server with a correct, writable -sd/--store_dir path."],"exampleFix":"// before (container)\nvolumeMounts: [{mountPath: /data, readOnly: true}]\n// after\nvolumeMounts: [{mountPath: /data, readOnly: false}]\n// plus: chown nats:nats /data/jetstream","handlingStrategy":"retry","validationCode":"info, err := os.Stat(storeDir)\nif err != nil || !info.IsDir() { return errors.New(\"jetstream store dir missing or inaccessible\") }\nif err := syscall.Access(storeDir, syscall.O_RDWR); err != nil { return errors.New(\"store dir not writable\") }","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"could not create snapshots directory\") { /* check fs perms/mount and retry */ }","preventionTips":["Ensure the server user owns/can write the -sd store directory.","Mount storage read-write; monitor disk space."],"tags":["jetstream","filesystem","snapshot","permissions"],"backgroundTag":"filesystem-write-failed","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}