node-opcua-client 2.167.0 → 2.168.0
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/dist/private/client_base_impl.js +88 -81
- package/dist/private/client_base_impl.js.map +1 -1
- package/dist/private/reconnection/client_publish_engine_reconnection.js +54 -45
- package/dist/private/reconnection/client_publish_engine_reconnection.js.map +1 -1
- package/dist/private/reconnection/reconnection.d.ts +1 -1
- package/dist/private/reconnection/reconnection.js +199 -280
- package/dist/private/reconnection/reconnection.js.map +1 -1
- package/package.json +41 -42
- package/source/private/client_base_impl.ts +142 -193
- package/source/private/reconnection/client_publish_engine_reconnection.ts +67 -60
- package/source/private/reconnection/reconnection.ts +253 -344
|
@@ -4,22 +4,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.republish = republish;
|
|
7
|
-
const async_1 = __importDefault(require("async"));
|
|
8
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
8
|
const node_opcua_assert_1 = __importDefault(require("node-opcua-assert"));
|
|
10
9
|
const node_opcua_debug_1 = require("node-opcua-debug");
|
|
11
10
|
const node_opcua_status_code_1 = require("node-opcua-status-code");
|
|
12
11
|
const node_opcua_types_1 = require("node-opcua-types");
|
|
13
|
-
const util_1 = require("util");
|
|
14
12
|
const client_subscription_reconnection_1 = require("./client_subscription_reconnection");
|
|
15
13
|
const reconnection_1 = require("./reconnection");
|
|
16
14
|
const debugLog = (0, node_opcua_debug_1.make_debugLog)("RECONNECTION");
|
|
17
15
|
const doDebug = (0, node_opcua_debug_1.checkDebugFlag)("RECONNECTION");
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const sendRepublishFunc = (callback2) => {
|
|
22
|
-
(0, node_opcua_assert_1.default)(isFinite(subscription.lastSequenceNumber) && subscription.lastSequenceNumber + 1 >= 0);
|
|
16
|
+
function _sendRepublish(session, subscription) {
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
(0, node_opcua_assert_1.default)(Number.isFinite(subscription.lastSequenceNumber) && subscription.lastSequenceNumber + 1 >= 0);
|
|
23
19
|
const request = new node_opcua_types_1.RepublishRequest({
|
|
24
20
|
retransmitSequenceNumber: subscription.lastSequenceNumber + 1,
|
|
25
21
|
subscriptionId: subscription.subscriptionId
|
|
@@ -31,54 +27,61 @@ function _republish(engine, subscription, callback) {
|
|
|
31
27
|
}
|
|
32
28
|
if (!session || session._closeEventHasBeenEmitted) {
|
|
33
29
|
debugLog("ClientPublishEngine#_republish aborted ");
|
|
34
|
-
|
|
35
|
-
isDone = true;
|
|
36
|
-
return callback2();
|
|
30
|
+
return resolve({ isDone: true });
|
|
37
31
|
}
|
|
38
32
|
session.republish(request, (err, response) => {
|
|
33
|
+
if (!response) {
|
|
34
|
+
reject(err);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
39
37
|
const statusCode = err ? node_opcua_status_code_1.StatusCodes.Bad : response.responseHeader.serviceResult;
|
|
40
38
|
if (!err && (statusCode.equals(node_opcua_status_code_1.StatusCodes.Good) || statusCode.equals(node_opcua_status_code_1.StatusCodes.BadMessageNotAvailable))) {
|
|
41
|
-
// reprocess notification message
|
|
39
|
+
// reprocess notification message and keep going
|
|
42
40
|
if (statusCode.equals(node_opcua_status_code_1.StatusCodes.Good)) {
|
|
43
41
|
subscription.onNotificationMessage(response.notificationMessage);
|
|
44
42
|
}
|
|
43
|
+
return resolve({ isDone: false });
|
|
45
44
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
err = new Error(response.responseHeader.serviceResult.toString());
|
|
49
|
-
}
|
|
50
|
-
debugLog(" _send_republish ends with ", err.message);
|
|
51
|
-
isDone = true;
|
|
45
|
+
if (!err) {
|
|
46
|
+
err = new Error(response.responseHeader.serviceResult.toString());
|
|
52
47
|
}
|
|
53
|
-
|
|
48
|
+
debugLog(" _send_republish ends with ", err.message);
|
|
49
|
+
reject(err);
|
|
54
50
|
});
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
async function _republish(engine, subscription) {
|
|
54
|
+
const session = engine.session;
|
|
55
|
+
// loop until done (all messages re-published or error)
|
|
56
|
+
let isDone = false;
|
|
57
|
+
while (!isDone) {
|
|
58
|
+
// yield to event loop before each iteration
|
|
59
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
60
|
+
const result = await _sendRepublish(session, subscription);
|
|
61
|
+
isDone = result.isDone;
|
|
62
|
+
}
|
|
63
|
+
debugLog("nbPendingPublishRequest = ", engine.nbPendingPublishRequests);
|
|
64
|
+
debugLog(" _republish ends with ", "null");
|
|
65
65
|
}
|
|
66
|
-
function __askSubscriptionRepublish(engine, subscription
|
|
67
|
-
|
|
66
|
+
async function __askSubscriptionRepublish(engine, subscription) {
|
|
67
|
+
try {
|
|
68
|
+
await _republish(engine, subscription);
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
68
71
|
// prettier-ignore
|
|
69
72
|
{
|
|
70
73
|
const _err = (0, reconnection_1._shouldNotContinue2)(subscription);
|
|
71
74
|
if (_err) {
|
|
72
|
-
|
|
75
|
+
throw _err;
|
|
73
76
|
}
|
|
74
77
|
}
|
|
75
|
-
|
|
76
|
-
debugLog("__askSubscriptionRepublish--------------------- err =",
|
|
77
|
-
if (
|
|
78
|
+
const error = err;
|
|
79
|
+
debugLog("__askSubscriptionRepublish--------------------- err =", error.message);
|
|
80
|
+
if (error.message.match(/BadSessionInvalid/)) {
|
|
78
81
|
// _republish failed because session is not valid anymore on server side.
|
|
79
|
-
|
|
82
|
+
throw error;
|
|
80
83
|
}
|
|
81
|
-
if (
|
|
84
|
+
if (error.message.match(/SubscriptionIdInvalid/)) {
|
|
82
85
|
// _republish failed because subscriptionId is not valid anymore on server side.
|
|
83
86
|
//
|
|
84
87
|
// This could happen when the subscription has timed out and has been deleted by server
|
|
@@ -89,15 +92,18 @@ function __askSubscriptionRepublish(engine, subscription, callback) {
|
|
|
89
92
|
// the event handlers
|
|
90
93
|
//
|
|
91
94
|
debugLog(chalk_1.default.bgWhite.red("__askSubscriptionRepublish failed " + " subscriptionId is not valid anymore on server side."));
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
.catch((err) => callback(err));
|
|
95
|
+
await (0, client_subscription_reconnection_1.recreateSubscriptionAndMonitoredItem)(subscription);
|
|
96
|
+
return;
|
|
95
97
|
}
|
|
96
|
-
if (
|
|
98
|
+
if (error.message.match(/|MessageNotAvailable/)) {
|
|
97
99
|
// start engine and start monitoring
|
|
98
100
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
+
}
|
|
102
|
+
// check after successful republish too
|
|
103
|
+
const _err = (0, reconnection_1._shouldNotContinue2)(subscription);
|
|
104
|
+
if (_err) {
|
|
105
|
+
throw _err;
|
|
106
|
+
}
|
|
101
107
|
}
|
|
102
108
|
function republish(engine, callback) {
|
|
103
109
|
// After re-establishing the connection the Client shall call Republish in a loop, starting with
|
|
@@ -111,9 +117,12 @@ function republish(engine, callback) {
|
|
|
111
117
|
* call Republish continuously until all Notification messages of
|
|
112
118
|
* un-acknowledged notifications are reprocessed.
|
|
113
119
|
*/
|
|
114
|
-
const
|
|
115
|
-
|
|
120
|
+
const processAll = async () => {
|
|
121
|
+
const entries = Object.entries(engine.subscriptionMap);
|
|
122
|
+
for (const [_subscriptionId, subscription] of entries) {
|
|
123
|
+
await __askSubscriptionRepublish(engine, subscription);
|
|
124
|
+
}
|
|
116
125
|
};
|
|
117
|
-
|
|
126
|
+
processAll().then(() => callback()).catch(() => callback());
|
|
118
127
|
}
|
|
119
128
|
//# sourceMappingURL=client_publish_engine_reconnection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client_publish_engine_reconnection.js","sourceRoot":"","sources":["../../../source/private/reconnection/client_publish_engine_reconnection.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"client_publish_engine_reconnection.js","sourceRoot":"","sources":["../../../source/private/reconnection/client_publish_engine_reconnection.ts"],"names":[],"mappings":";;;;;AAqIA,8BAoBC;AAzJD,kDAA0B;AAC1B,0EAAuC;AACvC,uDAAiE;AACjE,mEAAqD;AACrD,uDAA4E;AAI5E,yFAA0F;AAC1F,iDAAqD;AAErD,MAAM,QAAQ,GAAG,IAAA,gCAAa,EAAC,cAAc,CAAC,CAAC;AAC/C,MAAM,OAAO,GAAG,IAAA,iCAAc,EAAC,cAAc,CAAC,CAAC;AAE/C,SAAS,cAAc,CACnB,OAA0B,EAC1B,YAAoC;IAEpC,OAAO,IAAI,OAAO,CAAsB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACxD,IAAA,2BAAM,EAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,kBAAkB,CAAC,IAAI,YAAY,CAAC,kBAAkB,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;QAErG,MAAM,OAAO,GAAG,IAAI,mCAAgB,CAAC;YACjC,wBAAwB,EAAE,YAAY,CAAC,kBAAkB,GAAG,CAAC;YAC7D,cAAc,EAAE,YAAY,CAAC,cAAc;SAC9C,CAAC,CAAC;QAEH,iBAAiB;QACjB,IAAI,OAAO,EAAE,CAAC;YACV,iBAAiB;YACjB,QAAQ,CACJ,eAAK,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,qCAAqC,CAAC,EAC/D,OAAO,CAAC,cAAc,EACtB,4BAA4B,EAC5B,OAAO,CAAC,wBAAwB,CACnC,CAAC;QACN,CAAC;QAED,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,yBAAyB,EAAE,CAAC;YAChD,QAAQ,CAAC,yCAAyC,CAAC,CAAC;YACpD,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;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C,YAAY,CAAC,CAAC;YACzD,OAAO;QACX,CAAC;QACD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,sBAAsB,CAAC,EAAE,CAAC;YAC9C,oCAAoC;QACxC,CAAC;IACL,CAAC;IACD,uCAAuC;IACvC,MAAM,IAAI,GAAG,IAAA,kCAAmB,EAAC,YAAY,CAAC,CAAC;IAC/C,IAAI,IAAI,EAAE,CAAC;QACP,MAAM,IAAI,CAAC;IACf,CAAC;AACL,CAAC;AAED,SAAgB,SAAS,CAAC,MAA+B,EAAE,QAAoB;IAC3E,gGAAgG;IAChG,kGAAkG;IAClG,qCAAqC;IACrC,uGAAuG;IACvG,YAAY;IACZ,oGAAoG;IACpG,0BAA0B;IAC1B;;;OAGG;IACH,MAAM,UAAU,GAAG,KAAK,IAAI,EAAE;QAC1B,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QACvD,KAAK,MAAM,CAAC,eAAe,EAAE,YAAY,CAAC,IAAI,OAAO,EAAE,CAAC;YACpD,MAAM,0BAA0B,CAAC,MAAM,EAAE,YAAsC,CAAC,CAAC;QACrF,CAAC;IACL,CAAC,CAAC;IAEF,UAAU,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC;AAChE,CAAC"}
|
|
@@ -8,5 +8,5 @@ export declare function _shouldNotContinue(session: ClientSessionImpl): Error |
|
|
|
8
8
|
export declare function _shouldNotContinue2(subscription: ClientSubscriptionImpl): Error | null;
|
|
9
9
|
type EmptyCallback = (err?: Error) => void;
|
|
10
10
|
export declare function repair_client_session(client: IClientBase, session: ClientSessionImpl, callback: EmptyCallback): void;
|
|
11
|
-
export declare function repair_client_sessions(client: IClientBase, callback: (err?: Error) => void): void
|
|
11
|
+
export declare function repair_client_sessions(client: IClientBase, callback: (err?: Error) => void): Promise<void>;
|
|
12
12
|
export {};
|