{"record":{"id":"950332aff5b1faf0","repo":"dgraph-io/dgraph","slug":"not-able-to-create-new-file-v","errorCode":null,"errorMessage":"not able to create new file %v","messagePattern":"not able to create new file (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"x/log_writer.go","lineNumber":62,"sourceCode":"\tEncryptionKey []byte\n\n\tmu     sync.Mutex\n\tsize   int64\n\tfile   *os.File\n\twriter *bufio.Writer\n\tcloser *z.Closer\n\t// To manage order of cleaning old logs files\n\tmanageChannel chan bool\n}\n\nfunc (l *LogWriter) Init() (*LogWriter, error) {\n\tif l == nil {\n\t\treturn nil, nil\n\t}\n\n\tl.manageOldLogs()\n\tif err := l.open(); err != nil {\n\t\treturn nil, fmt.Errorf(\"not able to create new file %v\", err)\n\t}\n\tl.closer = z.NewCloser(2)\n\tl.manageChannel = make(chan bool, 1)\n\tgo func() {\n\t\tdefer l.closer.Done()\n\t\tfor {\n\t\t\tselect {\n\t\t\tcase <-l.manageChannel:\n\t\t\t\tl.manageOldLogs()\n\t\t\tcase <-l.closer.HasBeenClosed():\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}()\n\n\tgo l.flushPeriodic()\n\treturn l, nil\n}","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/x/log_writer.go#L44-L80","documentation":"Error logged by the log writer (x/log_writer.go) when creating a new log file fails, e.g. due to permissions, a bad path, or disk errors. The target file is reported via %v. Fix by checking the log directory's existence, permissions, and available disk space.","triggerScenarios":"Calling Init (directly or via newFileSink/InitLogger) with a log file path in a nonexistent directory, a read-only filesystem, or a path with insufficient permissions.","commonSituations":"Wrong log dir path in config, container running as non-root writing to /var/log, read-only root filesystem in Kubernetes, or disk full.","solutions":["Verify the log file's parent directory exists and create it (os.MkdirAll) before Init","Check filesystem permissions for the process user","Ensure the volume is writable (not mounted read-only) and has free space","Fix the configured log path in your Dgraph config/env"],"exampleFix":"// before\ns, err := x.Init(\"/var/log/dgraph/dgraph.log\", false)\n// after: ensure directory exists\ndir := filepath.Dir(logPath)\nif err := os.MkdirAll(dir, 0755); err != nil { log.Fatal(err) }\ns, err := x.Init(logPath, false)","handlingStrategy":"try-catch","validationCode":"dir := filepath.Dir(logPath)\nif err := os.MkdirAll(dir, 0755); err != nil { return err }\nif f, err := os.OpenFile(logPath, os.O_APPEND|os.O_CREATE, 0644); err != nil { return err } else { f.Close() }","typeGuard":null,"tryCatchPattern":"sink, err := x.Init(logPath, false)\nif err != nil {\n  return fmt.Errorf(\"logger init failed (%s): %w\", logPath, err)\n}","preventionTips":["Create the log directory at startup before Init","Run containers with a writable volume for logs","Check disk space and permissions in deployment probes"],"tags":["go","logging","filesystem"],"backgroundTag":"log-file-open-failed","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}