@node-red/runtime 4.1.3 → 4.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/nodes/Node.js CHANGED
@@ -322,6 +322,7 @@ Node.prototype.close = function(removed) {
322
322
  // The callback takes a 'done' callback and (maybe) the removed flag
323
323
  promises.push(
324
324
  new Promise((resolve) => {
325
+ var resolved = false;
325
326
  try {
326
327
  var args = [];
327
328
  if (callback.length === 2) {
@@ -329,13 +330,19 @@ Node.prototype.close = function(removed) {
329
330
  args.push(!!removed);
330
331
  }
331
332
  args.push(() => {
332
- resolve();
333
+ if (!resolved) {
334
+ resolved = true;
335
+ resolve();
336
+ }
333
337
  });
334
338
  callback.apply(node, args);
335
339
  } catch(err) {
336
340
  // TODO: error thrown in node async close callback
337
341
  // We've never logged this properly.
338
- resolve();
342
+ if (!resolved) {
343
+ resolved = true;
344
+ resolve();
345
+ }
339
346
  }
340
347
  })
341
348
  );
@@ -155,6 +155,7 @@ function LocalFileSystem(config){
155
155
  }
156
156
  this.pendingWrites = {};
157
157
  this.knownCircularRefs = {};
158
+ this.closing = false;
158
159
 
159
160
  if (config.hasOwnProperty('flushInterval')) {
160
161
  this.flushInterval = Math.max(0,config.flushInterval) * 1000;
@@ -233,16 +234,19 @@ LocalFileSystem.prototype.open = function(){
233
234
 
234
235
  LocalFileSystem.prototype.close = function(){
235
236
  var self = this;
236
- if (this.cache && this._pendingWriteTimeout) {
237
- clearTimeout(this._pendingWriteTimeout);
238
- delete this._pendingWriteTimeout;
237
+ this.closing = true;
238
+ if (this.cache) {
239
+ if (this._pendingWriteTimeout) {
240
+ clearTimeout(this._pendingWriteTimeout);
241
+ delete this._pendingWriteTimeout;
242
+ }
239
243
  this.flushInterval = 0;
244
+ // Always flush pending writes on close, even if no timeout was pending
240
245
  self.writePromise = self.writePromise.then(function(){
241
246
  return self._flushPendingWrites.call(self).catch(function(err) {
242
247
  log.error(log._("context.localfilesystem.error-write",{message:err.toString()}));
243
248
  });
244
249
  });
245
-
246
250
  }
247
251
  return this.writePromise;
248
252
  }
@@ -298,8 +302,9 @@ LocalFileSystem.prototype.set = function(scope, key, value, callback) {
298
302
  if (this.cache) {
299
303
  this.cache.set(scope,key,value,callback);
300
304
  this.pendingWrites[scope] = true;
301
- if (this._pendingWriteTimeout) {
302
- // there's a pending write which will handle this
305
+ if (this._pendingWriteTimeout || this.closing) {
306
+ // there's a pending write which will handle this,
307
+ // or we're closing and the close() flush will handle it
303
308
  return;
304
309
  } else {
305
310
  this._pendingWriteTimeout = setTimeout(function() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-red/runtime",
3
- "version": "4.1.3",
3
+ "version": "4.1.4",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./lib/index.js",
6
6
  "repository": {
@@ -16,8 +16,8 @@
16
16
  }
17
17
  ],
18
18
  "dependencies": {
19
- "@node-red/registry": "4.1.3",
20
- "@node-red/util": "4.1.3",
19
+ "@node-red/registry": "4.1.4",
20
+ "@node-red/util": "4.1.4",
21
21
  "async-mutex": "0.5.0",
22
22
  "clone": "2.1.2",
23
23
  "cronosjs": "1.7.1",