hashicorp/nomad · error

failed to rotate log files: %v

Error message

failed to rotate log files: %v

What it means

Thrown by logFile.rotate when renaming the active log file to its timestamped replacement (or subsequent rotation bookkeeping) fails; the wrapped os error is surfaced so log writes report rotation failure to callers.

Source

Thrown at command/agent/log_file.go:97

	l.BytesWritten = stat.Size()
	l.LastCreated = l.createTime(stat)
	return nil
}

func (l *logFile) rotate() error {
	// Get the time from the last point of contact
	timeElapsed := time.Since(l.LastCreated)
	// Rotate if we hit the byte file limit or the time limit
	if (l.BytesWritten >= int64(l.MaxBytes) && (l.MaxBytes > 0)) || timeElapsed >= l.duration {
		l.FileInfo.Close()

		// Move current log file to a timestamped file.
		rotateTime := now()
		rotatefileName := fmt.Sprintf(l.fileNamePattern(), strconv.FormatInt(rotateTime.UnixNano(), 10))
		oldPath := l.FileInfo.Name()
		newPath := filepath.Join(l.logPath, rotatefileName)
		if err := os.Rename(oldPath, newPath); err != nil {
			return fmt.Errorf("failed to rotate log files: %v", err)
		}

		if err := l.pruneFiles(); err != nil {
			return fmt.Errorf("failed to prune log files: %v", err)
		}
		return l.openNew()
	}
	return nil
}

func (l *logFile) pruneFiles() error {
	if l.MaxFiles == 0 {
		return nil
	}
	pattern := l.fileNamePattern()
	//get all the files that match the log file pattern
	globExpression := filepath.Join(l.logPath, fmt.Sprintf(pattern, "*"))
	matches, err := filepath.Glob(globExpression)

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Check filesystem permissions on the log directory and the old log file
  2. Verify the disk is not full and the path is writable by the Nomad agent user
  3. Check for stale file locks or the file being open by another process (e.g. log collector)
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at command/agent/log_file.go:97 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/8745fb53bc5e62ff. Report an issue: GitHub.