dgraph-io/dgraph · error

not able to create new file %v

Error message

not able to create new file %v

What it means

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.

Source

Thrown at x/log_writer.go:62

	EncryptionKey []byte

	mu     sync.Mutex
	size   int64
	file   *os.File
	writer *bufio.Writer
	closer *z.Closer
	// To manage order of cleaning old logs files
	manageChannel chan bool
}

func (l *LogWriter) Init() (*LogWriter, error) {
	if l == nil {
		return nil, nil
	}

	l.manageOldLogs()
	if err := l.open(); err != nil {
		return nil, fmt.Errorf("not able to create new file %v", err)
	}
	l.closer = z.NewCloser(2)
	l.manageChannel = make(chan bool, 1)
	go func() {
		defer l.closer.Done()
		for {
			select {
			case <-l.manageChannel:
				l.manageOldLogs()
			case <-l.closer.HasBeenClosed():
				return
			}
		}
	}()

	go l.flushPeriodic()
	return l, nil
}

View on GitHub (pinned to 759e242be6)

Solutions

  1. Verify the log file's parent directory exists and create it (os.MkdirAll) before Init
  2. Check filesystem permissions for the process user
  3. Ensure the volume is writable (not mounted read-only) and has free space
  4. Fix the configured log path in your Dgraph config/env

Example fix

// before
s, err := x.Init("/var/log/dgraph/dgraph.log", false)
// after: ensure directory exists
dir := filepath.Dir(logPath)
if err := os.MkdirAll(dir, 0755); err != nil { log.Fatal(err) }
s, err := x.Init(logPath, false)
Defensive patterns

Strategy: try-catch

Validate before calling

dir := filepath.Dir(logPath)
if err := os.MkdirAll(dir, 0755); err != nil { return err }
if f, err := os.OpenFile(logPath, os.O_APPEND|os.O_CREATE, 0644); err != nil { return err } else { f.Close() }

Try / catch

sink, err := x.Init(logPath, false)
if err != nil {
  return fmt.Errorf("logger init failed (%s): %w", logPath, err)
}

Prevention

When it happens

Trigger: 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.

Common situations: Wrong log dir path in config, container running as non-root writing to /var/log, read-only root filesystem in Kubernetes, or disk full.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/950332aff5b1faf0. Report an issue: GitHub.