lutzroeder/netron · error · Error

File '${this._file}' last modified time changed.

Error message

File '${this._file}' last modified time changed.

What it means

Thrown by the lazy file-backed reader when the file's modification time (mtimeMs) no longer matches the mtime captured when the stream was opened. The reader memory-maps/buffers lazily and uses the mtime as a consistency check so it never returns mixed-verson data if the file changed underneath it.

Source

Thrown at source/node.js:94

        }
        if (!this._buffer || this._position < this._offset || this._position + length > this._offset + this._buffer.length) {
            this._offset = this._position;
            const length = Math.min(0x10000000, this._length - this._offset);
            if (!this._buffer || length !== this._buffer.length) {
                this._buffer = new Uint8Array(length);
            }
            this._read(this._buffer, this._offset);
        }
        const position = this._position;
        this._position += length;
        return position - this._offset;
    }

    _read(buffer, offset) {
        const descriptor = fs.openSync(this._file, 'r');
        const stat = fs.statSync(this._file);
        if (stat.mtimeMs !== this._mtime) {
            throw new Error(`File '${this._file}' last modified time changed.`);
        }
        try {
            // 'fs.readSync' length is a signed 32-bit value. Read in chunks to support buffers larger than 2 GB.
            const length = buffer.length;
            for (let position = 0; position < length;) {
                const size = Math.min(0x40000000, length - position);
                position += fs.readSync(descriptor, buffer, position, size, offset + this._start + position);
            }
        } finally {
            fs.closeSync(descriptor);
        }
    }
};

export const FileStream = node.FileStream;

View on GitHub (pinned to d8a543f5f8)

Solutions

  1. Copy the file to a stable temporary path and open the stream on the copy.
  2. Ensure no concurrent writer (build pipeline, sync client) touches the file during parsing.
  3. Re-open the stream after the file stabilizes (open, read, close promptly).

Example fix

// before
const stream = new file.Stream(path);
await longOperation(); // file gets rewritten meanwhile
stream.read(...); // throws

// after
const tmp = path + '.snapshot';
fs.copyFileSync(path, tmp);
const stream = new file.Stream(tmp);
Defensive patterns

Strategy: validation

Validate before calling

const statBefore = fs.statSync(path);
// ... open stream and parse fully, then:
const statAfter = fs.statSync(path);
if (statBefore.mtimeMs !== statAfter.mtimeMs) {
    console.warn('File changed during parse; results may be stale');
}

Try / catch

try { data = stream.read(n); } catch (e) { if (/last modified time changed/.test(e.message)) { /* re-open stream on stable copy and retry once */ } else throw e; }

Prevention

When it happens

Trigger: Opening a stream on a file, then modifying/overwriting that file (re-export, sync tool, editor save, log rotation) before any read that triggers _read(); the stat inside _read detects the new mtime and throws.

Common situations: Watching a directory while another process rewrites models, downloading directly over the file being parsed, antivirus/indexers touching the file, or tests that mutate fixtures mid-parse.

Related errors


AI-assisted analysis of lutzroeder/netron@d8a543f5f8 (2026-08-27). Data as JSON: /api/errors/a19187bdd5b60dc9. Report an issue: GitHub.