Fixed rare agent update exception on the server.
Ylian Saint-Hilaire committed
Mar 9, 2019 at 15:04 UTC
2b32db76bba1c35f8f4debd822c65e99c53e534d
1 file changed
+3
meshagent.js
+3
@@ -98,6 +98,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
98
if (obj.dbMeshKey) { delete obj.dbMeshKey; }
99
if (obj.connectTime) { delete obj.connectTime; }
100
if (obj.agentInfo) { delete obj.agentInfo; }
101
+ if (obj.agentExeInfo) { delete obj.agentExeInfo; }
102
ws.removeAllListeners(["message", "close", "error"]);
103
};
104
@@ -218,6 +219,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
219
if (obj.agentExeInfo.data == null) {
220
// Read the agent from disk
221
parent.fs.open(obj.agentExeInfo.path, 'r', function (err, fd) {
222
+ if (obj.agentExeInfo == null) return; // Agent disconnected during this call.
223
if (err) { return console.error(err); }
224
obj.agentUpdate = { ptr: 0, buf: Buffer.alloc(agentUpdateBlockSize + 4), fd: fd, taskid: taskid };
225
@@ -294,6 +296,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
296
if (obj.agentExeInfo.data == null) {
297
// Read the agent from disk
298
parent.fs.read(obj.agentUpdate.fd, obj.agentUpdate.buf, 4, agentUpdateBlockSize, obj.agentUpdate.ptr, function (err, bytesRead, buffer) {
299
+ if ((obj.agentExeInfo == null) || (obj.agentUpdate == null)) return; // Agent disconnected during this async call.
300
if ((err != null) || (bytesRead < 0)) {
301
// Error reading the agent file, stop here.
302
try { parent.fs.close(obj.agentUpdate.fd); } catch (ex) { }