1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Fix race condition in non-cache lfs context

Fixes #1888
This commit is contained in:
Nick O'Leary 2018-09-17 10:31:00 +01:00
parent 9777af7cb5
commit c1d50e82e1
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -140,9 +140,9 @@ function stringify(value) {
function LocalFileSystem(config){ function LocalFileSystem(config){
this.config = config; this.config = config;
this.storageBaseDir = getBasePath(this.config); this.storageBaseDir = getBasePath(this.config);
this.writePromise = Promise.resolve();
if (config.hasOwnProperty('cache')?config.cache:true) { if (config.hasOwnProperty('cache')?config.cache:true) {
this.cache = MemoryStore({}); this.cache = MemoryStore({});
this.writePromise = Promise.resolve();
} }
this.pendingWrites = {}; this.pendingWrites = {};
this.knownCircularRefs = {}; this.knownCircularRefs = {};
@ -219,9 +219,8 @@ LocalFileSystem.prototype.close = function(){
clearTimeout(this._pendingWriteTimeout); clearTimeout(this._pendingWriteTimeout);
delete this._pendingWriteTimeout; delete this._pendingWriteTimeout;
this.flushInterval = 0; this.flushInterval = 0;
return this.writePromise;
} }
return Promise.resolve(); return this.writePromise;
} }
LocalFileSystem.prototype.get = function(scope, key, callback) { LocalFileSystem.prototype.get = function(scope, key, callback) {
@ -290,7 +289,7 @@ LocalFileSystem.prototype.set = function(scope, key, value, callback) {
} else if (callback && typeof callback !== 'function') { } else if (callback && typeof callback !== 'function') {
throw new Error("Callback must be a function"); throw new Error("Callback must be a function");
} else { } else {
loadFile(storagePath + ".json").then(function(data){ self.writePromise = self.writePromise.then(function() { return loadFile(storagePath + ".json") }).then(function(data){
var obj = data ? JSON.parse(data) : {} var obj = data ? JSON.parse(data) : {}
if (!Array.isArray(key)) { if (!Array.isArray(key)) {
key = [key]; key = [key];