mirror of https://github.com/node-red/node-red.git
Merge pull request #5462 from Dennis-SEG/fix/localfilesystem-race-condition-clean
fix: prevent race condition in localfilesystem context store during shutdownpull/5467/head^2
commit
89db8f0d4f
|
|
@ -155,6 +155,7 @@ function LocalFileSystem(config){
|
|||
}
|
||||
this.pendingWrites = {};
|
||||
this.knownCircularRefs = {};
|
||||
this.closing = false;
|
||||
|
||||
if (config.hasOwnProperty('flushInterval')) {
|
||||
this.flushInterval = Math.max(0,config.flushInterval) * 1000;
|
||||
|
|
@ -233,16 +234,19 @@ LocalFileSystem.prototype.open = function(){
|
|||
|
||||
LocalFileSystem.prototype.close = function(){
|
||||
var self = this;
|
||||
if (this.cache && this._pendingWriteTimeout) {
|
||||
clearTimeout(this._pendingWriteTimeout);
|
||||
delete this._pendingWriteTimeout;
|
||||
this.closing = true;
|
||||
if (this.cache) {
|
||||
if (this._pendingWriteTimeout) {
|
||||
clearTimeout(this._pendingWriteTimeout);
|
||||
delete this._pendingWriteTimeout;
|
||||
}
|
||||
this.flushInterval = 0;
|
||||
// Always flush pending writes on close, even if no timeout was pending
|
||||
self.writePromise = self.writePromise.then(function(){
|
||||
return self._flushPendingWrites.call(self).catch(function(err) {
|
||||
log.error(log._("context.localfilesystem.error-write",{message:err.toString()}));
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
return this.writePromise;
|
||||
}
|
||||
|
|
@ -298,8 +302,9 @@ LocalFileSystem.prototype.set = function(scope, key, value, callback) {
|
|||
if (this.cache) {
|
||||
this.cache.set(scope,key,value,callback);
|
||||
this.pendingWrites[scope] = true;
|
||||
if (this._pendingWriteTimeout) {
|
||||
// there's a pending write which will handle this
|
||||
if (this._pendingWriteTimeout || this.closing) {
|
||||
// there's a pending write which will handle this,
|
||||
// or we're closing and the close() flush will handle it
|
||||
return;
|
||||
} else {
|
||||
this._pendingWriteTimeout = setTimeout(function() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue