Updated PTHI error handling, to retry for up to 5 seconds
Bryan Roe committed
Jul 14, 2021 at 15:11 UTC
5b1b33a59020db55d3e37f292d416c7ca5349f52
2 files changed
+40
-42
agents/modules_meshcmd/amt-mei.js
+20
-21
@@ -17,6 +17,21 @@ limitations under the License.
17
var Q = require('queue');
18
var g_internal = null;
19
20
+function retry_pthi_later()
21
+{
22
+ if (++g_internal.errorCount < 20)
23
+ {
24
+ g_internal.timeout = setTimeout(function (p)
25
+ {
26
+ p.connect(require('heci').GUIDS.AMT, { noPipeline: 1 });
27
+ }, 250, this);
28
+ }
29
+ else
30
+ {
31
+ this.Parent.emit('error', 'PTHI Connection could not be established');
32
+ }
33
+}
34
+
35
function amt_heci()
36
{
37
var emitterUtils = require('events').inherits(this);
@@ -29,7 +44,7 @@ function amt_heci()
44
var that = this;
45
if (g_internal == null)
46
{
32
- g_internal = { _rq: new Q(), _amt: null };
47
+ g_internal = { _rq: new Q(), _amt: null, errorCount: 0 };
48
g_internal._setupPTHI = function _g_setupPTHI()
49
{
50
console.info1('setupPTHI()');
@@ -42,7 +57,7 @@ function amt_heci()
57
this._amt.on('error', function _amtOnError(e)
58
{
59
console.info1('PTHIError: ' + e);
45
- if (this.Parent._rq.isEmpty())
60
+ if (g_internal._rq.isEmpty())
61
{
62
console.info1(' Queue is empty');
63
this.Parent.emit('error', e); // No pending requests, so propagate the error up
@@ -51,22 +66,13 @@ function amt_heci()
66
{
67
console.info1(' Queue is NOT empty');
68
54
- // There is a pending request, so fail the pending request
55
- var user = this.Parent._rq.deQueue();
56
- var params = user.optional;
57
- var callback = user.func;
58
- params.unshift({ Status: -1 }); // Relay an error
59
- callback.apply(this.Parent, params);
60
-
61
- if (!this.Parent._rq.isEmpty())
62
- {
63
- // There are still more pending requests, so try to re-helpconnect MEI
64
- this.connect(heci.GUIDS.AMT, { noPipeline: 1 });
65
- }
69
+ // Try again
70
+ retry_pthi_later.call(this);
71
}
72
});
73
this._amt.on('connect', function _amtOnConnect()
74
{
75
+ g_internal.errorCount = 0;
76
this.on('data', function _amtOnData(chunk)
77
{
78
//console.log("Received: " + chunk.length + " bytes");
@@ -125,13 +131,6 @@ function amt_heci()
131
header.writeUInt32LE(arguments[0] | 0x04000000, 4);
132
header.writeUInt32LE(arguments[1] == null ? 0 : arguments[1].length, 8);
133
128
- //this._rq.enQueue({ cmd: arguments[0], func: arguments[2], optional: args, send: (arguments[1] == null ? header : Buffer.concat([header, arguments[1]])) });
129
- //if(!this._amt)
130
- //{
131
- // this._setupPTHI();
132
- // this._amt.connect(heci.GUIDS.AMT, { noPipeline: 1 });
133
- //}
134
-
134
g_internal._rq.enQueue({ cmd: arguments[0], func: arguments[2], optional: args, send: (arguments[1] == null ? header : Buffer.concat([header, arguments[1]])) });
135
if (!g_internal._amt)
136
{
agents/modules_meshcore/amt-mei.js
+20
-21
@@ -17,6 +17,21 @@ limitations under the License.
17
var Q = require('queue');
18
var g_internal = null;
19
20
+function retry_pthi_later()
21
+{
22
+ if (++g_internal.errorCount < 20)
23
+ {
24
+ g_internal.timeout = setTimeout(function (p)
25
+ {
26
+ p.connect(require('heci').GUIDS.AMT, { noPipeline: 1 });
27
+ }, 250, this);
28
+ }
29
+ else
30
+ {
31
+ this.Parent.emit('error', 'PTHI Connection could not be established');
32
+ }
33
+}
34
+
35
function amt_heci()
36
{
37
var emitterUtils = require('events').inherits(this);
@@ -29,7 +44,7 @@ function amt_heci()
44
var that = this;
45
if (g_internal == null)
46
{
32
- g_internal = { _rq: new Q(), _amt: null };
47
+ g_internal = { _rq: new Q(), _amt: null, errorCount: 0 };
48
g_internal._setupPTHI = function _g_setupPTHI()
49
{
50
console.info1('setupPTHI()');
@@ -42,7 +57,7 @@ function amt_heci()
57
this._amt.on('error', function _amtOnError(e)
58
{
59
console.info1('PTHIError: ' + e);
45
- if (this.Parent._rq.isEmpty())
60
+ if (g_internal._rq.isEmpty())
61
{
62
console.info1(' Queue is empty');
63
this.Parent.emit('error', e); // No pending requests, so propagate the error up
@@ -51,22 +66,13 @@ function amt_heci()
66
{
67
console.info1(' Queue is NOT empty');
68
54
- // There is a pending request, so fail the pending request
55
- var user = this.Parent._rq.deQueue();
56
- var params = user.optional;
57
- var callback = user.func;
58
- params.unshift({ Status: -1 }); // Relay an error
59
- callback.apply(this.Parent, params);
60
-
61
- if (!this.Parent._rq.isEmpty())
62
- {
63
- // There are still more pending requests, so try to re-helpconnect MEI
64
- this.connect(heci.GUIDS.AMT, { noPipeline: 1 });
65
- }
69
+ // Try again
70
+ retry_pthi_later.call(this);
71
}
72
});
73
this._amt.on('connect', function _amtOnConnect()
74
{
75
+ g_internal.errorCount = 0;
76
this.on('data', function _amtOnData(chunk)
77
{
78
//console.log("Received: " + chunk.length + " bytes");
@@ -125,13 +131,6 @@ function amt_heci()
131
header.writeUInt32LE(arguments[0] | 0x04000000, 4);
132
header.writeUInt32LE(arguments[1] == null ? 0 : arguments[1].length, 8);
133
128
- //this._rq.enQueue({ cmd: arguments[0], func: arguments[2], optional: args, send: (arguments[1] == null ? header : Buffer.concat([header, arguments[1]])) });
129
- //if(!this._amt)
130
- //{
131
- // this._setupPTHI();
132
- // this._amt.connect(heci.GUIDS.AMT, { noPipeline: 1 });
133
- //}
134
-
134
g_internal._rq.enQueue({ cmd: arguments[0], func: arguments[2], optional: args, send: (arguments[1] == null ? header : Buffer.concat([header, arguments[1]])) });
135
if (!g_internal._amt)
136
{