From 4dc9c7714c9667f74cdc3c2fc430ea8cc263d078 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Sat, 11 Jun 2016 22:53:27 +0100 Subject: [PATCH] Clear node context on close Fixes #870 --- red/runtime/nodes/Node.js | 11 +++++++++-- red/runtime/nodes/context.js | 3 ++- test/red/runtime/nodes/context_spec.js | 11 +++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/red/runtime/nodes/Node.js b/red/runtime/nodes/Node.js index 3e936417e..ed0503ec5 100644 --- a/red/runtime/nodes/Node.js +++ b/red/runtime/nodes/Node.js @@ -1,5 +1,5 @@ /** - * Copyright 2014, 2015 IBM Corp. + * Copyright 2014, 2016 IBM Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -99,8 +99,15 @@ Node.prototype.close = function() { } } if (promises.length > 0) { - return when.settle(promises); + return when.settle(promises).then(function() { + if (this._context) { + context.delete(this._alias||this.id,this.z); + } + }); } else { + if (this._context) { + context.delete(this._alias||this.id,this.z); + } return; } }; diff --git a/red/runtime/nodes/context.js b/red/runtime/nodes/context.js index c19cabff9..7587d4ff9 100644 --- a/red/runtime/nodes/context.js +++ b/red/runtime/nodes/context.js @@ -1,5 +1,5 @@ /** - * Copyright 2015 IBM Corp. + * Copyright 2015, 2016 IBM Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -76,5 +76,6 @@ module.exports = { globalContext = createContext("global",settings.functionGlobalContext || {}); }, get: getContext, + delete: deleteContext, clean:clean }; diff --git a/test/red/runtime/nodes/context_spec.js b/test/red/runtime/nodes/context_spec.js index 7dd3cbcf3..688e480cf 100644 --- a/test/red/runtime/nodes/context_spec.js +++ b/test/red/runtime/nodes/context_spec.js @@ -108,4 +108,15 @@ describe('context', function() { context2.global.get("foo").should.eql("test"); }); + it('deletes context',function() { + var context = Context.get("1","flowA"); + should.not.exist(context.get("foo")); + context.set("foo","abc"); + context.get("foo").should.eql("abc"); + + Context.delete("1","flowA"); + context = Context.get("1","flowA"); + should.not.exist(context.get("foo")); + }) + });