{"record":{"id":"a19187bdd5b60dc9","repo":"lutzroeder/netron","slug":"file-this-file-last-modified-time-changed","errorCode":null,"errorMessage":"File '${this._file}' last modified time changed.","messagePattern":"File '(.+?)' last modified time changed\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"source/node.js","lineNumber":94,"sourceCode":"        }\n        if (!this._buffer || this._position < this._offset || this._position + length > this._offset + this._buffer.length) {\n            this._offset = this._position;\n            const length = Math.min(0x10000000, this._length - this._offset);\n            if (!this._buffer || length !== this._buffer.length) {\n                this._buffer = new Uint8Array(length);\n            }\n            this._read(this._buffer, this._offset);\n        }\n        const position = this._position;\n        this._position += length;\n        return position - this._offset;\n    }\n\n    _read(buffer, offset) {\n        const descriptor = fs.openSync(this._file, 'r');\n        const stat = fs.statSync(this._file);\n        if (stat.mtimeMs !== this._mtime) {\n            throw new Error(`File '${this._file}' last modified time changed.`);\n        }\n        try {\n            // 'fs.readSync' length is a signed 32-bit value. Read in chunks to support buffers larger than 2 GB.\n            const length = buffer.length;\n            for (let position = 0; position < length;) {\n                const size = Math.min(0x40000000, length - position);\n                position += fs.readSync(descriptor, buffer, position, size, offset + this._start + position);\n            }\n        } finally {\n            fs.closeSync(descriptor);\n        }\n    }\n};\n\nexport const FileStream = node.FileStream;\n","sourceCodeStart":76,"sourceCodeEnd":110,"githubUrl":"https://github.com/lutzroeder/netron/blob/d8a543f5f847ef596aa58858d6adcf5d75545f7f/source/node.js#L76-L110","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Copy the file to a stable temporary path and open the stream on the copy.","Ensure no concurrent writer (build pipeline, sync client) touches the file during parsing.","Re-open the stream after the file stabilizes (open, read, close promptly)."],"exampleFix":"// before\nconst stream = new file.Stream(path);\nawait longOperation(); // file gets rewritten meanwhile\nstream.read(...); // throws\n\n// after\nconst tmp = path + '.snapshot';\nfs.copyFileSync(path, tmp);\nconst stream = new file.Stream(tmp);","handlingStrategy":"validation","validationCode":"const statBefore = fs.statSync(path);\n// ... open stream and parse fully, then:\nconst statAfter = fs.statSync(path);\nif (statBefore.mtimeMs !== statAfter.mtimeMs) {\n    console.warn('File changed during parse; results may be stale');\n}","typeGuard":null,"tryCatchPattern":"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; }","preventionTips":["Parse from an immutable copy (tmp snapshot) of files that may be rewritten.","Open, read, and close streams promptly instead of holding them across long operations.","Exclude model directories from editors/sync tools during processing."],"tags":["file","mtime","concurrent-modification","stream"],"backgroundTag":"file-modified-during-read","analyzedSha":"d8a543f5f847ef596aa58858d6adcf5d75545f7f","analyzedAt":"2026-08-27T19:21:42.082Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}