core-3nweb-client-lib 0.26.0 → 0.26.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.
|
@@ -16,9 +16,11 @@ export declare class ClientsSideImpl implements ClientsSide {
|
|
|
16
16
|
processInterimCallReply(fnCallNum: number, body: EnvelopeBody): void;
|
|
17
17
|
processEndCallReply(fnCallNum: number, body: EnvelopeBody): void;
|
|
18
18
|
processCallError(fnCallNum: number, body: EnvelopeBody): void;
|
|
19
|
+
private retryWithOtherCallNum;
|
|
19
20
|
private nextFnCallNum;
|
|
20
21
|
caller(): Caller;
|
|
21
22
|
private startCall;
|
|
23
|
+
private setupFnCall;
|
|
22
24
|
startPromiseCall(path: string[], req: EnvelopeBody): Promise<EnvelopeBody>;
|
|
23
25
|
startObservableCall(path: string[], req: EnvelopeBody, obs: Subject<EnvelopeBody>): () => void;
|
|
24
26
|
registerClientDrop(o: any, srvRef: ObjectReference<any>): void;
|
|
@@ -21,6 +21,7 @@ const protobuf_msg_1 = require("./protobuf-msg");
|
|
|
21
21
|
const deferred_1 = require("../lib-common/processes/deferred");
|
|
22
22
|
const weakref_1 = require("../lib-common/weakref");
|
|
23
23
|
const connector_1 = require("./connector");
|
|
24
|
+
const MAX_DUPLICATE_ATTEMPTS = 100;
|
|
24
25
|
// XXX can have an optimized use of WeakRef and FinalizationRegistry, when
|
|
25
26
|
// these are available.
|
|
26
27
|
class ClientsSideImpl {
|
|
@@ -104,7 +105,13 @@ class ClientsSideImpl {
|
|
|
104
105
|
if (!call) {
|
|
105
106
|
return;
|
|
106
107
|
}
|
|
108
|
+
this.fnCalls.delete(fnCallNum);
|
|
107
109
|
const err = (body ? protobuf_msg_1.errFromMsg(protobuf_msg_1.errBodyType.unpack(body)) : undefined);
|
|
110
|
+
if (err && (err.type === 'ipc')
|
|
111
|
+
&& err.duplicateFnCallNum) {
|
|
112
|
+
this.retryWithOtherCallNum(call);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
108
115
|
if (call.obs) {
|
|
109
116
|
call.obs.error(err);
|
|
110
117
|
}
|
|
@@ -114,7 +121,32 @@ class ClientsSideImpl {
|
|
|
114
121
|
else {
|
|
115
122
|
// XXX log presence of fn call without fields to signal reply
|
|
116
123
|
}
|
|
117
|
-
|
|
124
|
+
}
|
|
125
|
+
retryWithOtherCallNum(call) {
|
|
126
|
+
if (call.countOfDuplicateFnCallNum) {
|
|
127
|
+
call.countOfDuplicateFnCallNum += 1;
|
|
128
|
+
if (call.countOfDuplicateFnCallNum >= MAX_DUPLICATE_ATTEMPTS) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
call.countOfDuplicateFnCallNum = 1;
|
|
134
|
+
}
|
|
135
|
+
const fnCallNum = this.nextFnCallNum();
|
|
136
|
+
call.reqEnv.headers.fnCallNum.value = fnCallNum;
|
|
137
|
+
this.fnCalls.set(fnCallNum, call);
|
|
138
|
+
try {
|
|
139
|
+
this.sendMsg(call.reqEnv);
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
this.fnCalls.delete(fnCallNum);
|
|
143
|
+
if (call.deferred) {
|
|
144
|
+
call.deferred.reject(err);
|
|
145
|
+
}
|
|
146
|
+
else if (call.obs) {
|
|
147
|
+
call.obs.error(err);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
118
150
|
}
|
|
119
151
|
nextFnCallNum() {
|
|
120
152
|
while (this.fnCalls.has(this.fnCallCounter)) {
|
|
@@ -141,21 +173,27 @@ class ClientsSideImpl {
|
|
|
141
173
|
};
|
|
142
174
|
return callerWrap;
|
|
143
175
|
}
|
|
144
|
-
startCall(
|
|
176
|
+
startCall(reqEnv) {
|
|
145
177
|
if (this.isStopped) {
|
|
146
178
|
throw connector_1.makeIPCException({ 'ipcNotConnected': true });
|
|
147
179
|
}
|
|
148
|
-
this.sendMsg(
|
|
180
|
+
this.sendMsg(reqEnv);
|
|
181
|
+
}
|
|
182
|
+
setupFnCall(path, body, deferred, obs) {
|
|
183
|
+
const fnCallNum = this.nextFnCallNum();
|
|
184
|
+
const reqEnv = {
|
|
149
185
|
headers: { fnCallNum: protobuf_msg_1.toVal(fnCallNum), msgType: 'start', path },
|
|
150
186
|
body: protobuf_msg_1.toOptVal(body)
|
|
151
|
-
}
|
|
187
|
+
};
|
|
188
|
+
this.fnCalls.set(fnCallNum, { deferred, obs, reqEnv });
|
|
189
|
+
return reqEnv;
|
|
152
190
|
}
|
|
153
191
|
startPromiseCall(path, req) {
|
|
154
192
|
const deferred = deferred_1.defer();
|
|
155
|
-
const
|
|
156
|
-
|
|
193
|
+
const reqEnv = this.setupFnCall(path, req, deferred, undefined);
|
|
194
|
+
const fnCallNum = reqEnv.headers.fnCallNum.value;
|
|
157
195
|
try {
|
|
158
|
-
this.startCall(
|
|
196
|
+
this.startCall(reqEnv);
|
|
159
197
|
return deferred.promise;
|
|
160
198
|
}
|
|
161
199
|
catch (err) {
|
|
@@ -164,10 +202,10 @@ class ClientsSideImpl {
|
|
|
164
202
|
}
|
|
165
203
|
}
|
|
166
204
|
startObservableCall(path, req, obs) {
|
|
167
|
-
const
|
|
168
|
-
|
|
205
|
+
const reqEnv = this.setupFnCall(path, req, undefined, obs);
|
|
206
|
+
const fnCallNum = reqEnv.headers.fnCallNum.value;
|
|
169
207
|
try {
|
|
170
|
-
this.startCall(
|
|
208
|
+
this.startCall(reqEnv);
|
|
171
209
|
return () => this.sendCallCancellation(fnCallNum);
|
|
172
210
|
}
|
|
173
211
|
catch (err) {
|