@flowfuse/device-agent
Advanced tools
Comparing version 2.4.0 to 2.4.1
@@ -0,1 +1,7 @@ | ||
#### 2.4.1: Release | ||
- Ensure local ws connections are closed on disconnect (#255) @knolleary | ||
- Update `package.json` with user defined node-red version (#254) @Steve-Mcl | ||
- If NR process has exited, dont send or wait for sigxxx (#252) @Steve-Mcl | ||
#### 2.4.0: Release | ||
@@ -2,0 +8,0 @@ |
@@ -29,3 +29,3 @@ const { info, warn, debug } = require('../logging/log') | ||
// off if connect fails | ||
this.reconnectDelay = 500 | ||
this.reconnectDelay = 1500 | ||
@@ -90,3 +90,3 @@ const forgeURL = new URL(config.forgeURL) | ||
// Reset reconnectDelay | ||
this.reconnectDelay = 500 | ||
this.reconnectDelay = 1500 | ||
this.socket.on('message', async (message) => { | ||
@@ -266,8 +266,4 @@ // a message coming over the tunnel from a remote editor | ||
// .close will get called | ||
const reconnectDelay = this.reconnectDelay | ||
// Bump the delay for next time... 500ms, 1.5s, 4.5s, 10s 10s 10s... | ||
this.reconnectDelay = Math.min(this.reconnectDelay * 3, 10000) | ||
this.reconnectTimeout = setTimeout(() => { | ||
this.connect() | ||
}, reconnectDelay) | ||
this.closeLocalWebSockets() | ||
this.reconnect() | ||
} else { | ||
@@ -280,5 +276,9 @@ // A 4004/'No tunnel' response means the platform doesn't think | ||
socket.on('error', (err) => { | ||
warn(`Editor tunnel error: ${err}`) | ||
console.warn('socket.error', err) | ||
this.close(1006, err.message) // 1006 = Abnormal Closure | ||
if (err.code === 'ECONNREFUSED') { | ||
warn('Editor tunnel connection refused') | ||
} else { | ||
warn(`Editor tunnel error: ${err}`) | ||
console.warn('socket.error', err) | ||
this.close(1006, err.message) // 1006 = Abnormal Closure | ||
} | ||
}) | ||
@@ -292,8 +292,5 @@ this.socket = socket | ||
reason = reason || 'Normal Closure' | ||
// loop through each local comms ws client and close its connection | ||
Object.keys(this.wsClients || {}).forEach(c => { | ||
this.wsClients[c]?.close() | ||
delete this.wsClients[c] | ||
}) | ||
this.closeLocalWebSockets() | ||
// close the socket | ||
@@ -343,4 +340,22 @@ if (this.socket) { | ||
} | ||
closeLocalWebSockets () { | ||
// Close all ws clients to the local Node-RED | ||
Object.keys(this.wsClients || {}).forEach(c => { | ||
this.wsClients[c]?.close() | ||
delete this.wsClients[c] | ||
}) | ||
} | ||
reconnect () { | ||
warn(`Editor tunnel reconnecting in ${(this.reconnectDelay / 1000).toFixed(1)}s`) | ||
const reconnectDelay = this.reconnectDelay | ||
// Bump the delay for next time... 500ms, 1.5s, 4.5s, 10s 10s 10s... | ||
this.reconnectDelay = Math.min(this.reconnectDelay * 3, 10000) | ||
this.reconnectTimeout = setTimeout(() => { | ||
this.connect() | ||
}, reconnectDelay) | ||
} | ||
} | ||
module.exports = EditorTunnel |
@@ -319,5 +319,24 @@ const childProcess = require('child_process') | ||
async writeConfiguration (options = { updateSnapshot: true, updateSettings: true }) { | ||
let fullWrite = !options // default to full write if no options are provided | ||
// If this is an application owned device, the NR version might be user defined. | ||
// When the updateSettings flag is set, the user defined version is specified | ||
// and the versions differ, set the fullWrite flag to cause the package.json | ||
// to be updated and the installDependencies function to be run. | ||
const userDefinedNRVersion = this.settings?.editor?.nodeRedVersion | ||
if (userDefinedNRVersion && options?.updateSettings && this.agent?.currentOwnerType === 'application') { | ||
const pkg = await this.readPackage() | ||
const pkgNRVersion = pkg.modules?.['node-red'] || 'latest' | ||
const snapshotNRVersion = this.snapshot?.modules?.['node-red'] | ||
if ((pkgNRVersion !== userDefinedNRVersion || snapshotNRVersion !== userDefinedNRVersion)) { | ||
// package.json dependencies will be updated with snapshot.modules when writePackage is called | ||
// so here, we need to update the snapshot modules node-red version with the user defined version | ||
this.snapshot.modules['node-red'] = userDefinedNRVersion | ||
fullWrite = true | ||
} | ||
} | ||
info('Updating configuration files') | ||
await fs.mkdir(this.projectDir, { recursive: true }) | ||
if (!options || options.updateSnapshot) { | ||
if (fullWrite || options.updateSnapshot) { | ||
this.state = States.INSTALLING | ||
@@ -330,3 +349,3 @@ await this.writeNPMRCFile() | ||
} | ||
if (!options || options.updateSettings === true) { | ||
if (fullWrite || options.updateSettings === true) { | ||
await this.writeSettings() | ||
@@ -530,3 +549,3 @@ await this.writeNPMRCFile() | ||
if (this.proc) { | ||
if (this.proc && this.proc.exitCode === null) { | ||
// Setup a promise that will resolve once the process has really exited | ||
@@ -560,2 +579,4 @@ this.deferredStop = new Promise((resolve, reject) => { | ||
} else { | ||
this.proc && this.proc.unref() | ||
this.proc = undefined | ||
this.state = finalState | ||
@@ -562,0 +583,0 @@ await postShutdownOps() |
{ | ||
"name": "@flowfuse/device-agent", | ||
"version": "2.4.0", | ||
"version": "2.4.1", | ||
"description": "An Edge Agent for running Node-RED instances deployed from the FlowFuse Platform", | ||
@@ -5,0 +5,0 @@ "exports": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
284318
4418