Skip to content

Commit

Permalink
node-red-gpio: Add patch to perform explicit node cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
  • Loading branch information
jan-kiszka committed Nov 27, 2020
1 parent 633a77e commit 37ca6cf
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
From 110eec7a5a7452e8df14b67de4188dc8ea8eefd0 Mon Sep 17 00:00:00 2001
From: Jan Kiszka <jan.kiszka@siemens.com>
Date: Fri, 27 Nov 2020 08:14:14 +0100
Subject: [PATCH 3/3] Clean up mraa objects on node closing

Required as nodejs will only lazily delete the node objects, and we may
race with the next user requesting the resources.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
hardware/intel/mraa-gpio-ain.js | 1 +
hardware/intel/mraa-gpio-din.js | 1 +
hardware/intel/mraa-gpio-dout.js | 1 +
hardware/intel/mraa-gpio-led.js | 4 ++++
hardware/intel/mraa-gpio-pwm.js | 1 +
5 files changed, 8 insertions(+)

diff --git a/hardware/intel/mraa-gpio-ain.js b/hardware/intel/mraa-gpio-ain.js
index 65df93b..91e2b0b 100644
--- a/hardware/intel/mraa-gpio-ain.js
+++ b/hardware/intel/mraa-gpio-ain.js
@@ -22,6 +22,7 @@ module.exports = function(RED) {

this.on('close', function() {
clearInterval(this.timer);
+ node.x.close();
});
}
RED.nodes.registerType("mraa-gpio-ain", gpioAin);
diff --git a/hardware/intel/mraa-gpio-din.js b/hardware/intel/mraa-gpio-din.js
index 4ac983f..7eca35a 100644
--- a/hardware/intel/mraa-gpio-din.js
+++ b/hardware/intel/mraa-gpio-din.js
@@ -51,6 +51,7 @@ module.exports = function(RED) {
this.on('close', function() {
node.x.isr(m.EDGE_BOTH, null);
node.x.isrExit();
+ node.x.close();
});
}
RED.nodes.registerType("mraa-gpio-din", gpioDin);
diff --git a/hardware/intel/mraa-gpio-dout.js b/hardware/intel/mraa-gpio-dout.js
index 37d1429..fb3dbd8 100644
--- a/hardware/intel/mraa-gpio-dout.js
+++ b/hardware/intel/mraa-gpio-dout.js
@@ -24,6 +24,7 @@ module.exports = function(RED) {
});

this.on('close', function() {
+ node.p.close();
});
}
RED.nodes.registerType("mraa-gpio-dout", gpioDout);
diff --git a/hardware/intel/mraa-gpio-led.js b/hardware/intel/mraa-gpio-led.js
index aa613e9..5803296 100644
--- a/hardware/intel/mraa-gpio-led.js
+++ b/hardware/intel/mraa-gpio-led.js
@@ -64,6 +64,10 @@ module.exports = function(RED) {
}
});
this.on('close', function() {
+ this.led0.close();
+ this.led1.close();
+ this.led2.close();
+ this.led3.close();
});
}
RED.nodes.registerType("mraa-gpio-led", LEDNode);
diff --git a/hardware/intel/mraa-gpio-pwm.js b/hardware/intel/mraa-gpio-pwm.js
index 22b02cb..6a2469f 100644
--- a/hardware/intel/mraa-gpio-pwm.js
+++ b/hardware/intel/mraa-gpio-pwm.js
@@ -21,6 +21,7 @@ module.exports = function(RED) {

this.on('close', function() {
node.p.enable(false);
+ node.p.close();
});
}
RED.nodes.registerType("mraa-gpio-pwm", gpioPWM);
--
2.26.2

3 changes: 2 additions & 1 deletion recipes-app/node-red-gpio/node-red-gpio_0.0.6-IOT2050.bb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ MAINTAINER = "chao.zeng@siemens.com"
SRC_URI = " \
git://github.com/node-red/node-red-nodes;protocol=https \
file://0001-add-the-board-info-add-the-led-control-node.patch \
file://0002-extend-gpio-to-D19.patch"
file://0002-extend-gpio-to-D19.patch \
file://0003-Clean-up-mraa-objects-on-node-closing.patch"
SRCREV="3087e8e2a1ea189f394bca0a2af159ad859d7722"

S = "${WORKDIR}/git"
Expand Down

0 comments on commit 37ca6cf

Please sign in to comment.