node-red-contrib-ccu 4.17.0 → 4.17.1

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/CHANGELOG.md CHANGED
@@ -5,6 +5,22 @@ Notable changes to node-red-contrib-ccu. Format follows
5
5
  user-visible symptom and the cause, not the commit list (the release notes
6
6
  append commits automatically).
7
7
 
8
+ ## 4.17.1 (2026-11-29)
9
+
10
+ ### Fixed
11
+
12
+ - **A taken callback port crashed Node-RED.** When the BINRPC listening port
13
+ of a ccu-connection node was already in use - by a second connection node
14
+ with the same port, as a flow imported with a copy of the connection node
15
+ brings it, or by another process - Node-RED ended with
16
+ `listen EADDRINUSE` at every start (on RedMatic: only the safe mode was
17
+ left). Since 4.1.0 the error of the BINRPC callback server went unheard.
18
+ Now only that connection fails: its nodes show `port <n> in use`, the log
19
+ names the port and the connection node holding it, and the rest of the
20
+ runtime keeps running. The editor marks a connection node whose listening
21
+ port another connection node uses. Reported by HA_Beginner
22
+ (homematic-forum).
23
+
8
24
  ## 4.17.0 (2026-11-28)
9
25
 
10
26
  ### Changed
@@ -14,6 +14,23 @@
14
14
  ccuActivePairing = null;
15
15
  };
16
16
 
17
+ // a callback port another connection node listens on, too: only one of the two can open it
18
+ // (a flow imported with a copy of the connection node brings the same ports)
19
+ const ccuUniquePort = function (value) {
20
+ if (!value) {
21
+ return false;
22
+ }
23
+
24
+ let taken = false;
25
+ RED.nodes.eachConfig(node => {
26
+ if (node.type === 'ccu-connection' && node.id !== this.id && !node.d &&
27
+ (String(node.rpcBinPort) === String(value) || String(node.rpcXmlPort) === String(value))) {
28
+ taken = true;
29
+ }
30
+ });
31
+ return !taken || 'port ' + value + ' is used by another ccu-connection node';
32
+ };
33
+
17
34
  RED.nodes.registerType('ccu-connection', {
18
35
  category: 'config',
19
36
  defaults: {
@@ -45,8 +62,8 @@
45
62
  rpcPingTimeout: {value: 60},
46
63
  rpcInitAddress: {value: ''},
47
64
  rpcServerHost: {value: '', required: true},
48
- rpcBinPort: {value: '', required: true},
49
- rpcXmlPort: {value: '', required: true},
65
+ rpcBinPort: {value: '', required: true, validate: ccuUniquePort},
66
+ rpcXmlPort: {value: '', required: true, validate: ccuUniquePort},
50
67
 
51
68
  tls: {value: false},
52
69
  inSecure: {value: false},
@@ -107,6 +107,11 @@ module.exports = function (RED) {
107
107
 
108
108
  const ccu = {network: {listen: [], ports: []}};
109
109
 
110
+ // the callback ports the connection nodes of this runtime listen on, port -> {node, protocol}:
111
+ // a port that is taken names the config node holding it (two connection nodes with the same
112
+ // port, e.g. after importing a flow that carried a copy of one)
113
+ const callbackPorts = new Map();
114
+
110
115
  /**
111
116
  *
112
117
  * @param start
@@ -1127,7 +1132,7 @@ module.exports = function (RED) {
1127
1132
  }
1128
1133
 
1129
1134
  waiting = Boolean(waiting) && !connected;
1130
- if (connected && this.ifaceError[iface]) {
1135
+ if (connected && this.ifaceError[iface] && !this.serverError[iface]) {
1131
1136
  delete this.ifaceError[iface];
1132
1137
  this.ifaceStatus[iface] = null; // the nodes drop the error text
1133
1138
  }
@@ -4266,6 +4271,12 @@ module.exports = function (RED) {
4266
4271
  }
4267
4272
  });
4268
4273
 
4274
+ callbackPorts.forEach((holder, port) => {
4275
+ if (holder.node === this) {
4276
+ callbackPorts.delete(port);
4277
+ }
4278
+ });
4279
+
4269
4280
  this.logger.debug('queue binrpc server closing');
4270
4281
  calls.push(() => {
4271
4282
  return new Promise((resolve) => {
@@ -4336,6 +4347,54 @@ module.exports = function (RED) {
4336
4347
  return protocol + '://' + (this.rpcInitAddress || this.rpcServerHost) + ':' + port;
4337
4348
  }
4338
4349
 
4350
+ /**
4351
+ * The callback server of a protocol could not listen (the port is taken, the address is
4352
+ * gone): the interfaces that use it show why, the log names the port and who holds it, and
4353
+ * the rest of the runtime keeps running.
4354
+ * @param {string} protocol binrpc, http or https
4355
+ * @param {number} port the callback port
4356
+ * @param {Error} err the socket's error
4357
+ */
4358
+ callbackServerError(protocol, port, err) {
4359
+ const kind = protocol === 'binrpc' ? 'BINRPC' : 'XMLRPC';
4360
+ let text;
4361
+ if (err && err.code === 'EADDRINUSE') {
4362
+ const holder = callbackPorts.get(port);
4363
+ const other = holder && holder.node !== this ? holder.node : null;
4364
+ const name = other ? '"' + (other.name || other.id) + '" (' + other.id + ')' : '';
4365
+ this.logger.error(
4366
+ kind +
4367
+ ' listening port ' +
4368
+ port +
4369
+ ' is already in use' +
4370
+ (other
4371
+ ? ' by the ccu-connection config node ' + name
4372
+ : ' by another process or an older ccu-connection config node') +
4373
+ ' - give this config node "' +
4374
+ (this.name || this.id) +
4375
+ '" (' +
4376
+ this.id +
4377
+ ') another ' +
4378
+ kind +
4379
+ ' listening port, or delete one of the two',
4380
+ );
4381
+ text = 'port ' + port + ' in use' + (other ? ' by ' + (other.name || other.id) : '');
4382
+ } else {
4383
+ const message = (err && err.message) || String(err);
4384
+ this.logger.error(kind + ' server on port ' + port + ': ' + message);
4385
+ text = kind + ' server: ' + ((err && err.code) || message);
4386
+ }
4387
+
4388
+ Object.keys(this.ifaceTypes).forEach((iface) => {
4389
+ if (this.enabledIfaces.includes(iface) && this.ifaceTypes[iface].protocol === protocol) {
4390
+ this.serverError[iface] = text;
4391
+ this.ifaceError[iface] = text;
4392
+ this.ifaceStatus[iface] = false;
4393
+ }
4394
+ });
4395
+ this.pushStatus();
4396
+ }
4397
+
4339
4398
  /**
4340
4399
  *
4341
4400
  * @param iface
@@ -4349,6 +4408,7 @@ module.exports = function (RED) {
4349
4408
  this.servers[protocol] = rpc.createServer({host: this.rpcServerHost, port}, () => {
4350
4409
  // Todo homematic-xmlrpc and binrpc module: clarify onListening callback params
4351
4410
  this.logger.info(protocol === 'binrpc' ? 'binrpc' : 'xmlrpc', 'server listening on', url);
4411
+ callbackPorts.set(port, {node: this, protocol});
4352
4412
  this.serverError[iface] = null;
4353
4413
  });
4354
4414
  if (this.servers[protocol].httpServer) {
@@ -4363,12 +4423,11 @@ module.exports = function (RED) {
4363
4423
  this.servers[protocol].httpServer.headersTimeout = KEEP_ALIVE_TIMEOUT_MS + 5000;
4364
4424
  }
4365
4425
 
4366
- // Todo binrpc module: emit error event on server object to eliminate the reach-in
4367
- const errorEmitter = protocol === 'binrpc' ? this.servers[protocol].server : this.servers[protocol];
4368
- errorEmitter.on('error', (err) => {
4369
- this.logger.error(protocol + ' ' + err.message);
4370
- this.serverError[iface] = err.message;
4371
- });
4426
+ // Both modules re-emit the errors of their listening socket on the server object.
4427
+ // The listener sits there: binrpc >= 4.2 re-emits on its Server, and an 'error'
4428
+ // without a listener is thrown - a taken callback port (EADDRINUSE) ended the
4429
+ // whole Node-RED process instead of this connection.
4430
+ this.servers[protocol].on('error', (err) => this.callbackServerError(protocol, port, err));
4372
4431
 
4373
4432
  Object.keys(this.rpcMethods).forEach((method) => {
4374
4433
  this.servers[protocol].on(method, (err, parameters, callback) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-ccu",
3
- "version": "4.17.0",
3
+ "version": "4.17.1",
4
4
  "license": "MIT",
5
5
  "main": "none",
6
6
  "keywords": [