@fluidframework/container-loader 2.0.0-internal.6.0.0 → 2.0.0-internal.6.1.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/CHANGELOG.md +4 -0
- package/dist/connectionManager.d.ts +3 -3
- package/dist/connectionManager.d.ts.map +1 -1
- package/dist/connectionManager.js +33 -24
- package/dist/connectionManager.js.map +1 -1
- package/dist/connectionStateHandler.d.ts +14 -14
- package/dist/connectionStateHandler.d.ts.map +1 -1
- package/dist/connectionStateHandler.js +17 -12
- package/dist/connectionStateHandler.js.map +1 -1
- package/dist/container.d.ts.map +1 -1
- package/dist/container.js +26 -38
- package/dist/container.js.map +1 -1
- package/dist/contracts.d.ts +11 -7
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js.map +1 -1
- package/dist/deltaManager.d.ts +4 -4
- package/dist/deltaManager.d.ts.map +1 -1
- package/dist/deltaManager.js +5 -4
- package/dist/deltaManager.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/protocol.d.ts +4 -2
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +23 -1
- package/dist/protocol.js.map +1 -1
- package/lib/connectionManager.d.ts +3 -3
- package/lib/connectionManager.d.ts.map +1 -1
- package/lib/connectionManager.js +33 -24
- package/lib/connectionManager.js.map +1 -1
- package/lib/connectionStateHandler.d.ts +14 -14
- package/lib/connectionStateHandler.d.ts.map +1 -1
- package/lib/connectionStateHandler.js +17 -12
- package/lib/connectionStateHandler.js.map +1 -1
- package/lib/container.d.ts.map +1 -1
- package/lib/container.js +27 -39
- package/lib/container.js.map +1 -1
- package/lib/contracts.d.ts +11 -7
- package/lib/contracts.d.ts.map +1 -1
- package/lib/contracts.js.map +1 -1
- package/lib/deltaManager.d.ts +4 -4
- package/lib/deltaManager.d.ts.map +1 -1
- package/lib/deltaManager.js +5 -4
- package/lib/deltaManager.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/protocol.d.ts +4 -2
- package/lib/protocol.d.ts.map +1 -1
- package/lib/protocol.js +23 -1
- package/lib/protocol.js.map +1 -1
- package/package.json +13 -17
- package/src/connectionManager.ts +46 -31
- package/src/connectionStateHandler.ts +28 -36
- package/src/container.ts +46 -51
- package/src/contracts.ts +12 -6
- package/src/deltaManager.ts +19 -13
- package/src/packageVersion.ts +1 -1
- package/src/protocol.ts +33 -1
package/dist/protocol.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAEvE,OAAO,EACN,gBAAgB,IAAI,oBAAoB,EACxC,eAAe,EACf,iBAAiB,EACjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACN,mBAAmB,EACnB,qBAAqB,EAErB,yBAAyB,EAEzB,cAAc,EAEd,MAAM,sCAAsC,CAAC;AAG9C,eAAO,MAAM,kBAAkB,GAAa,CAAC;AAG7C,oBAAY,UAAU;IACrB,UAAU,SAAS;IACnB,WAAW,UAAU;IACrB,KAAK,UAAU;CACf;AAED;;GAEG;AACH,oBAAY,sBAAsB,GAAG,CACpC,UAAU,EAAE,mBAAmB,EAC/B,QAAQ,EAAE,eAAe,EACzB,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,MAAM,KAC7C,gBAAgB,CAAC;AAEtB,MAAM,WAAW,gBAAiB,SAAQ,oBAAoB;IAC7D,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,aAAa,CAAC,OAAO,EAAE,cAAc,OAAE;CACvC;AAED,qBAAa,eAAgB,SAAQ,iBAAkB,YAAW,gBAAgB;aAKhE,QAAQ,EAAE,cAAc;IACxC,OAAO,CAAC,QAAQ,CAAC,oBAAoB;gBAJrC,UAAU,EAAE,mBAAmB,EAC/B,cAAc,EAAE,eAAe,EAC/B,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,MAAM,EACjC,QAAQ,EAAE,cAAc,EACvB,oBAAoB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO;IAqB9D,cAAc,CACpB,OAAO,EAAE,yBAAyB,EAClC,KAAK,EAAE,OAAO,GACZ,qBAAqB;IAuBjB,aAAa,CAAC,OAAO,EAAE,cAAc;CAgC5C;AAED;;;;GAIG;AACH,wBAAgB,kCAAkC,CAAC,OAAO,EAAE,cAAc,WAWzE"}
|
package/dist/protocol.js
CHANGED
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.protocolHandlerShouldProcessSignal = exports.ProtocolHandler = exports.SignalType = exports.OnlyValidTermValue = void 0;
|
|
8
|
+
const driver_utils_1 = require("@fluidframework/driver-utils");
|
|
8
9
|
const protocol_base_1 = require("@fluidframework/protocol-base");
|
|
10
|
+
const protocol_definitions_1 = require("@fluidframework/protocol-definitions");
|
|
9
11
|
// "term" was an experimental feature that is being removed. The only safe value to use is 1.
|
|
10
12
|
exports.OnlyValidTermValue = 1;
|
|
11
13
|
// ADO: #1986: Start using enum from protocol-base.
|
|
@@ -16,9 +18,10 @@ var SignalType;
|
|
|
16
18
|
SignalType["Clear"] = "clear";
|
|
17
19
|
})(SignalType = exports.SignalType || (exports.SignalType = {}));
|
|
18
20
|
class ProtocolHandler extends protocol_base_1.ProtocolOpHandler {
|
|
19
|
-
constructor(attributes, quorumSnapshot, sendProposal, audience) {
|
|
21
|
+
constructor(attributes, quorumSnapshot, sendProposal, audience, shouldClientHaveLeft) {
|
|
20
22
|
super(attributes.minimumSequenceNumber, attributes.sequenceNumber, quorumSnapshot.members, quorumSnapshot.proposals, quorumSnapshot.values, sendProposal);
|
|
21
23
|
this.audience = audience;
|
|
24
|
+
this.shouldClientHaveLeft = shouldClientHaveLeft;
|
|
22
25
|
// Join / leave signals are ignored for "write" clients in favor of join / leave ops
|
|
23
26
|
this.quorum.on("addMember", (clientId, details) => audience.addMember(clientId, details.client));
|
|
24
27
|
this.quorum.on("removeMember", (clientId) => audience.removeMember(clientId));
|
|
@@ -26,6 +29,25 @@ class ProtocolHandler extends protocol_base_1.ProtocolOpHandler {
|
|
|
26
29
|
this.audience.addMember(clientId, details.client);
|
|
27
30
|
}
|
|
28
31
|
}
|
|
32
|
+
processMessage(message, local) {
|
|
33
|
+
const client = this.quorum.getMember(message.clientId);
|
|
34
|
+
// Check and report if we're getting messages from a clientId that we previously
|
|
35
|
+
// flagged as shouldHaveLeft, or from a client that's not in the quorum but should be
|
|
36
|
+
if (message.clientId != null) {
|
|
37
|
+
if (client === undefined && message.type !== protocol_definitions_1.MessageType.ClientJoin) {
|
|
38
|
+
// pre-0.58 error message: messageClientIdMissingFromQuorum
|
|
39
|
+
throw new Error("Remote message's clientId is missing from the quorum");
|
|
40
|
+
}
|
|
41
|
+
// Here checking canBeCoalescedByService is used as an approximation of "is benign to process despite being unexpected".
|
|
42
|
+
// It's still not good to see these messages from unexpected clientIds, but since they don't harm the integrity of the
|
|
43
|
+
// document we don't need to blow up aggressively.
|
|
44
|
+
if (this.shouldClientHaveLeft(message.clientId) && !(0, driver_utils_1.canBeCoalescedByService)(message)) {
|
|
45
|
+
// pre-0.58 error message: messageClientIdShouldHaveLeft
|
|
46
|
+
throw new Error("Remote message's clientId already should have left");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return super.processMessage(message, local);
|
|
50
|
+
}
|
|
29
51
|
processSignal(message) {
|
|
30
52
|
const innerContent = message.content;
|
|
31
53
|
switch (innerContent.type) {
|
package/dist/protocol.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,iEAIuC;
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,+DAAuE;AACvE,iEAIuC;AACvC,+EAQ8C;AAE9C,8FAA8F;AACjF,QAAA,kBAAkB,GAAG,CAAU,CAAC;AAE7C,mDAAmD;AACnD,IAAY,UAIX;AAJD,WAAY,UAAU;IACrB,iCAAmB,CAAA;IACnB,mCAAqB,CAAA;IACrB,6BAAe,CAAA;AAChB,CAAC,EAJW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAIrB;AAgBD,MAAa,eAAgB,SAAQ,iCAAiB;IACrD,YACC,UAA+B,EAC/B,cAA+B,EAC/B,YAAiD,EACjC,QAAwB,EACvB,oBAAmD;QAEpE,KAAK,CACJ,UAAU,CAAC,qBAAqB,EAChC,UAAU,CAAC,cAAc,EACzB,cAAc,CAAC,OAAO,EACtB,cAAc,CAAC,SAAS,EACxB,cAAc,CAAC,MAAM,EACrB,YAAY,CACZ,CAAC;QAVc,aAAQ,GAAR,QAAQ,CAAgB;QACvB,yBAAoB,GAApB,oBAAoB,CAA+B;QAWpE,oFAAoF;QACpF,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,CACjD,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,CAC5C,CAAC;QACF,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,cAAc,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC,QAAQ,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AK,MAAM,EAAE;wBAC3B,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;qBACrC;iBACD;gBACD,MAAM;aACN;YACD,KAAK,UAAU,CAAC,UAAU,CAAC,CAAC;gBAC3B,MAAM,SAAS,GAAG,YAAY,CAAC,OAAwB,CAAC;gBACxD,2DAA2D;gBAC3D,IAAI,SAAS,CAAC,MAAM,CAAC,IAAI,KAAK,MAAM,EAAE;oBACrC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,SAAS,CAAC,QAAQ,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;iBAC9D;gBACD,MAAM;aACN;YACD,KAAK,UAAU,CAAC,WAAW,CAAC,CAAC;gBAC5B,MAAM,YAAY,GAAG,YAAY,CAAC,OAAiB,CAAC;gBACpD,2DAA2D;gBAC3D,IAAI,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE,IAAI,KAAK,MAAM,EAAE;oBAC3D,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;iBACzC;gBACD,MAAM;aACN;YACD;gBACC,MAAM;SACP;IACF,CAAC;CACD;AArFD,0CAqFC;AAED;;;;GAIG;AACH,SAAgB,kCAAkC,CAAC,OAAuB;IACzE,gCAAgC;IAChC,IAAI,OAAO,CAAC,QAAQ,KAAK,IAAI,EAAE;QAC9B,MAAM,YAAY,GAAG,OAAO,CAAC,OAA6C,CAAC;QAC3E,OAAO,CACN,YAAY,CAAC,IAAI,KAAK,UAAU,CAAC,KAAK;YACtC,YAAY,CAAC,IAAI,KAAK,UAAU,CAAC,UAAU;YAC3C,YAAY,CAAC,IAAI,KAAK,UAAU,CAAC,WAAW,CAC5C,CAAC;KACF;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAXD,gFAWC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IAudienceOwner } from \"@fluidframework/container-definitions\";\nimport { canBeCoalescedByService } from \"@fluidframework/driver-utils\";\nimport {\n\tIProtocolHandler as IBaseProtocolHandler,\n\tIQuorumSnapshot,\n\tProtocolOpHandler,\n} from \"@fluidframework/protocol-base\";\nimport {\n\tIDocumentAttributes,\n\tIProcessMessageResult,\n\tISequencedClient,\n\tISequencedDocumentMessage,\n\tISignalClient,\n\tISignalMessage,\n\tMessageType,\n} from \"@fluidframework/protocol-definitions\";\n\n// \"term\" was an experimental feature that is being removed. The only safe value to use is 1.\nexport const OnlyValidTermValue = 1 as const;\n\n// ADO: #1986: Start using enum from protocol-base.\nexport enum SignalType {\n\tClientJoin = \"join\", // same value as MessageType.ClientJoin,\n\tClientLeave = \"leave\", // same value as MessageType.ClientLeave,\n\tClear = \"clear\", // used only by client for synthetic signals\n}\n\n/**\n * Function to be used for creating a protocol handler.\n */\nexport type ProtocolHandlerBuilder = (\n\tattributes: IDocumentAttributes,\n\tsnapshot: IQuorumSnapshot,\n\tsendProposal: (key: string, value: any) => number,\n) => IProtocolHandler;\n\nexport interface IProtocolHandler extends IBaseProtocolHandler {\n\treadonly audience: IAudienceOwner;\n\tprocessSignal(message: ISignalMessage);\n}\n\nexport class ProtocolHandler extends ProtocolOpHandler implements IProtocolHandler {\n\tconstructor(\n\t\tattributes: IDocumentAttributes,\n\t\tquorumSnapshot: IQuorumSnapshot,\n\t\tsendProposal: (key: string, value: any) => number,\n\t\tpublic readonly audience: IAudienceOwner,\n\t\tprivate readonly shouldClientHaveLeft: (clientId: string) => boolean,\n\t) {\n\t\tsuper(\n\t\t\tattributes.minimumSequenceNumber,\n\t\t\tattributes.sequenceNumber,\n\t\t\tquorumSnapshot.members,\n\t\t\tquorumSnapshot.proposals,\n\t\t\tquorumSnapshot.values,\n\t\t\tsendProposal,\n\t\t);\n\n\t\t// Join / leave signals are ignored for \"write\" clients in favor of join / leave ops\n\t\tthis.quorum.on(\"addMember\", (clientId, details) =>\n\t\t\taudience.addMember(clientId, details.client),\n\t\t);\n\t\tthis.quorum.on(\"removeMember\", (clientId) => audience.removeMember(clientId));\n\t\tfor (const [clientId, details] of this.quorum.getMembers()) {\n\t\t\tthis.audience.addMember(clientId, details.client);\n\t\t}\n\t}\n\n\tpublic processMessage(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t): IProcessMessageResult {\n\t\tconst client: ISequencedClient | undefined = this.quorum.getMember(message.clientId);\n\n\t\t// Check and report if we're getting messages from a clientId that we previously\n\t\t// flagged as shouldHaveLeft, or from a client that's not in the quorum but should be\n\t\tif (message.clientId != null) {\n\t\t\tif (client === undefined && message.type !== MessageType.ClientJoin) {\n\t\t\t\t// pre-0.58 error message: messageClientIdMissingFromQuorum\n\t\t\t\tthrow new Error(\"Remote message's clientId is missing from the quorum\");\n\t\t\t}\n\n\t\t\t// Here checking canBeCoalescedByService is used as an approximation of \"is benign to process despite being unexpected\".\n\t\t\t// It's still not good to see these messages from unexpected clientIds, but since they don't harm the integrity of the\n\t\t\t// document we don't need to blow up aggressively.\n\t\t\tif (this.shouldClientHaveLeft(message.clientId) && !canBeCoalescedByService(message)) {\n\t\t\t\t// pre-0.58 error message: messageClientIdShouldHaveLeft\n\t\t\t\tthrow new Error(\"Remote message's clientId already should have left\");\n\t\t\t}\n\t\t}\n\n\t\treturn super.processMessage(message, local);\n\t}\n\n\tpublic processSignal(message: ISignalMessage) {\n\t\tconst innerContent = message.content as { content: any; type: string };\n\t\tswitch (innerContent.type) {\n\t\t\tcase SignalType.Clear: {\n\t\t\t\tconst members = this.audience.getMembers();\n\t\t\t\tfor (const [clientId, client] of members) {\n\t\t\t\t\tif (client.mode === \"read\") {\n\t\t\t\t\t\tthis.audience.removeMember(clientId);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SignalType.ClientJoin: {\n\t\t\t\tconst newClient = innerContent.content as ISignalClient;\n\t\t\t\t// Ignore write clients - quorum will control such clients.\n\t\t\t\tif (newClient.client.mode === \"read\") {\n\t\t\t\t\tthis.audience.addMember(newClient.clientId, newClient.client);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase SignalType.ClientLeave: {\n\t\t\t\tconst leftClientId = innerContent.content as string;\n\t\t\t\t// Ignore write clients - quorum will control such clients.\n\t\t\t\tif (this.audience.getMember(leftClientId)?.mode === \"read\") {\n\t\t\t\t\tthis.audience.removeMember(leftClientId);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\n/**\n * Function to check whether the protocol handler should process the Signal.\n * The protocol handler should strictly handle only ClientJoin, ClientLeave\n * and Clear signal types.\n */\nexport function protocolHandlerShouldProcessSignal(message: ISignalMessage) {\n\t// Signal originates from server\n\tif (message.clientId === null) {\n\t\tconst innerContent = message.content as { content: unknown; type: string };\n\t\treturn (\n\t\t\tinnerContent.type === SignalType.Clear ||\n\t\t\tinnerContent.type === SignalType.ClientJoin ||\n\t\t\tinnerContent.type === SignalType.ClientLeave\n\t\t);\n\t}\n\treturn false;\n}\n"]}
|
|
@@ -7,7 +7,7 @@ import { ICriticalContainerError, IDeltaQueue, ReadOnlyInfo } from "@fluidframew
|
|
|
7
7
|
import { IDocumentService } from "@fluidframework/driver-definitions";
|
|
8
8
|
import { ConnectionMode, IClient, IClientConfiguration, IClientDetails, IDocumentMessage, ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
|
|
9
9
|
import { ITelemetryLoggerExt } from "@fluidframework/telemetry-utils";
|
|
10
|
-
import { ReconnectMode, IConnectionManager, IConnectionManagerFactoryArgs } from "./contracts";
|
|
10
|
+
import { ReconnectMode, IConnectionManager, IConnectionManagerFactoryArgs, IConnectionStateChangeReason } from "./contracts";
|
|
11
11
|
/**
|
|
12
12
|
* Implementation of IConnectionManager, used by Container class
|
|
13
13
|
* Implements constant connectivity to relay service, by reconnecting in case of lost connection or error.
|
|
@@ -91,7 +91,7 @@ export declare class ConnectionManager implements IConnectionManager {
|
|
|
91
91
|
* Enables or disables automatic reconnecting.
|
|
92
92
|
* Will throw an error if reconnectMode set to Never.
|
|
93
93
|
*/
|
|
94
|
-
setAutoReconnect(mode: ReconnectMode): void;
|
|
94
|
+
setAutoReconnect(mode: ReconnectMode, reason: IConnectionStateChangeReason): void;
|
|
95
95
|
/**
|
|
96
96
|
* Sends signal to runtime (and data stores) to be read-only.
|
|
97
97
|
* Hosts may have read only views, indicating to data stores that no edits are allowed.
|
|
@@ -111,7 +111,7 @@ export declare class ConnectionManager implements IConnectionManager {
|
|
|
111
111
|
*/
|
|
112
112
|
forceReadonly(readonly: boolean): void;
|
|
113
113
|
private set_readonlyPermissions;
|
|
114
|
-
connect(reason:
|
|
114
|
+
connect(reason: IConnectionStateChangeReason, connectionMode?: ConnectionMode): void;
|
|
115
115
|
private connectCore;
|
|
116
116
|
/**
|
|
117
117
|
* Start the connection. Any error should result in container being closed.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connectionManager.d.ts","sourceRoot":"","sources":["../src/connectionManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAe,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEpF,OAAO,EACN,uBAAuB,EACvB,WAAW,EACX,YAAY,EACZ,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAEN,gBAAgB,EAGhB,MAAM,oCAAoC,CAAC;AAU5C,OAAO,EACN,cAAc,EACd,OAAO,EACP,oBAAoB,EACpB,cAAc,EACd,gBAAgB,EAGhB,yBAAyB,EAOzB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAA8B,MAAM,iCAAiC,CAAC;AAClG,OAAO,EACN,aAAa,EACb,kBAAkB,EAClB,6BAA6B,EAE7B,MAAM,aAAa,CAAC;AAwHrB;;;;GAIG;AACH,qBAAa,iBAAkB,YAAW,kBAAkB;IAoL1D,OAAO,CAAC,QAAQ,CAAC,eAAe;a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AC,QAAQ,CAAC,yBAAyB,CAIxC;IAEF,OAAO,CAAC,QAAQ,CAAC,YAAY,CAE3B;CACF"}
|
package/lib/connectionManager.js
CHANGED
|
@@ -280,7 +280,10 @@ export class ConnectionManager {
|
|
|
280
280
|
// Ensure that things like triggerConnect() will short circuit
|
|
281
281
|
this._reconnectMode = ReconnectMode.Never;
|
|
282
282
|
this._outbound.clear();
|
|
283
|
-
const disconnectReason =
|
|
283
|
+
const disconnectReason = {
|
|
284
|
+
text: "Closing DeltaManager",
|
|
285
|
+
error,
|
|
286
|
+
};
|
|
284
287
|
// This raises "disconnect" event if we have active connection.
|
|
285
288
|
this.disconnectFromDeltaStream(disconnectReason);
|
|
286
289
|
if (switchToReadonly) {
|
|
@@ -294,12 +297,12 @@ export class ConnectionManager {
|
|
|
294
297
|
* Enables or disables automatic reconnecting.
|
|
295
298
|
* Will throw an error if reconnectMode set to Never.
|
|
296
299
|
*/
|
|
297
|
-
setAutoReconnect(mode) {
|
|
300
|
+
setAutoReconnect(mode, reason) {
|
|
298
301
|
assert(mode !== ReconnectMode.Never && this._reconnectMode !== ReconnectMode.Never, 0x278 /* "API is not supported for non-connecting or closed container" */);
|
|
299
302
|
this._reconnectMode = mode;
|
|
300
303
|
if (mode !== ReconnectMode.Enabled) {
|
|
301
304
|
// immediately disconnect - do not rely on service eventually dropping connection.
|
|
302
|
-
this.disconnectFromDeltaStream(
|
|
305
|
+
this.disconnectFromDeltaStream(reason);
|
|
303
306
|
}
|
|
304
307
|
}
|
|
305
308
|
/**
|
|
@@ -342,12 +345,12 @@ export class ConnectionManager {
|
|
|
342
345
|
// host logic error.
|
|
343
346
|
this.logger.sendErrorEvent({ eventName: "ForceReadonlyPendingChanged" });
|
|
344
347
|
}
|
|
345
|
-
reconnect = this.disconnectFromDeltaStream("Force readonly");
|
|
348
|
+
reconnect = this.disconnectFromDeltaStream({ text: "Force readonly" });
|
|
346
349
|
}
|
|
347
350
|
this.props.readonlyChangeHandler(this.readonly);
|
|
348
351
|
if (reconnect) {
|
|
349
352
|
// reconnect if we disconnected from before.
|
|
350
|
-
this.triggerConnect("Force Readonly", "read");
|
|
353
|
+
this.triggerConnect({ text: "Force Readonly" }, "read");
|
|
351
354
|
}
|
|
352
355
|
}
|
|
353
356
|
}
|
|
@@ -359,8 +362,8 @@ export class ConnectionManager {
|
|
|
359
362
|
}
|
|
360
363
|
}
|
|
361
364
|
connect(reason, connectionMode) {
|
|
362
|
-
this.connectCore(reason, connectionMode).catch((
|
|
363
|
-
const normalizedError = normalizeError(
|
|
365
|
+
this.connectCore(reason, connectionMode).catch((e) => {
|
|
366
|
+
const normalizedError = normalizeError(e, { props: fatalConnectErrorProp });
|
|
364
367
|
this.props.closeHandler(normalizedError);
|
|
365
368
|
});
|
|
366
369
|
}
|
|
@@ -529,7 +532,7 @@ export class ConnectionManager {
|
|
|
529
532
|
* @param error - Error causing the disconnect if any.
|
|
530
533
|
* @returns A boolean that indicates if there was an existing connection (or pending connection) to disconnect
|
|
531
534
|
*/
|
|
532
|
-
disconnectFromDeltaStream(reason
|
|
535
|
+
disconnectFromDeltaStream(reason) {
|
|
533
536
|
this.pendingReconnect = false;
|
|
534
537
|
if (this.connection === undefined) {
|
|
535
538
|
if (this.pendingConnection !== undefined) {
|
|
@@ -553,7 +556,7 @@ export class ConnectionManager {
|
|
|
553
556
|
this._outbound.pause();
|
|
554
557
|
this._outbound.clear();
|
|
555
558
|
connection.dispose();
|
|
556
|
-
this.props.disconnectHandler(reason
|
|
559
|
+
this.props.disconnectHandler(reason);
|
|
557
560
|
this._connectionVerboseProps = {};
|
|
558
561
|
return true;
|
|
559
562
|
}
|
|
@@ -565,7 +568,10 @@ export class ConnectionManager {
|
|
|
565
568
|
this.pendingConnection.abort();
|
|
566
569
|
this.pendingConnection = undefined;
|
|
567
570
|
this.logger.sendTelemetryEvent({ eventName: "ConnectionCancelReceived" });
|
|
568
|
-
this.props.cancelConnectionHandler(
|
|
571
|
+
this.props.cancelConnectionHandler({
|
|
572
|
+
text: `Cancel Pending Connection due to ${reason.text}`,
|
|
573
|
+
error: reason.error,
|
|
574
|
+
});
|
|
569
575
|
}
|
|
570
576
|
/**
|
|
571
577
|
* Once we've successfully gotten a connection, we need to set up state, attach event listeners, and process
|
|
@@ -596,7 +602,7 @@ export class ConnectionManager {
|
|
|
596
602
|
this.set_readonlyPermissions(readonly);
|
|
597
603
|
if (this._disposed) {
|
|
598
604
|
// Raise proper events, Log telemetry event and close connection.
|
|
599
|
-
this.disconnectFromDeltaStream("ConnectionManager already closed");
|
|
605
|
+
this.disconnectFromDeltaStream({ text: "ConnectionManager already closed" });
|
|
600
606
|
return;
|
|
601
607
|
}
|
|
602
608
|
this._outbound.resume();
|
|
@@ -681,7 +687,7 @@ export class ConnectionManager {
|
|
|
681
687
|
* @returns A promise that resolves when the connection is reestablished or we stop trying
|
|
682
688
|
*/
|
|
683
689
|
reconnectOnError(requestedMode, error) {
|
|
684
|
-
this.reconnect(requestedMode, error.message, error).catch(this.props.closeHandler);
|
|
690
|
+
this.reconnect(requestedMode, { text: error.message, error }).catch(this.props.closeHandler);
|
|
685
691
|
}
|
|
686
692
|
/**
|
|
687
693
|
* Disconnect the current connection and reconnect.
|
|
@@ -690,20 +696,20 @@ export class ConnectionManager {
|
|
|
690
696
|
* @param error - Error reconnect information including whether or not to reconnect
|
|
691
697
|
* @returns A promise that resolves when the connection is reestablished or we stop trying
|
|
692
698
|
*/
|
|
693
|
-
async reconnect(requestedMode,
|
|
699
|
+
async reconnect(requestedMode, reason) {
|
|
694
700
|
// We quite often get protocol errors before / after observing nack/disconnect
|
|
695
701
|
// we do not want to run through same sequence twice.
|
|
696
702
|
// If we're already disconnected/disconnecting it's not appropriate to call this again.
|
|
697
703
|
assert(this.connection !== undefined, 0x0eb /* "Missing connection for reconnect" */);
|
|
698
|
-
this.disconnectFromDeltaStream(
|
|
704
|
+
this.disconnectFromDeltaStream(reason);
|
|
699
705
|
// We will always trigger reconnect, even if canRetry is false.
|
|
700
706
|
// Any truly fatal error state will result in container close upon attempted reconnect,
|
|
701
707
|
// which is a preferable to closing abruptly when a live connection fails.
|
|
702
|
-
if (error
|
|
708
|
+
if (reason.error?.canRetry === false) {
|
|
703
709
|
this.logger.sendTelemetryEvent({
|
|
704
710
|
eventName: "reconnectingDespiteFatalError",
|
|
705
711
|
reconnectMode: this.reconnectMode,
|
|
706
|
-
}, error);
|
|
712
|
+
}, reason.error);
|
|
707
713
|
}
|
|
708
714
|
if (this.reconnectMode === ReconnectMode.Never) {
|
|
709
715
|
// Do not raise container error if we are closing just because we lost connection.
|
|
@@ -716,9 +722,9 @@ export class ConnectionManager {
|
|
|
716
722
|
return;
|
|
717
723
|
}
|
|
718
724
|
// If the error tells us to wait before retrying, then do so.
|
|
719
|
-
const delayMs = getRetryDelayFromError(error);
|
|
720
|
-
if (error !== undefined && delayMs !== undefined) {
|
|
721
|
-
this.props.reconnectionDelayHandler(delayMs, error);
|
|
725
|
+
const delayMs = getRetryDelayFromError(reason.error);
|
|
726
|
+
if (reason.error !== undefined && delayMs !== undefined) {
|
|
727
|
+
this.props.reconnectionDelayHandler(delayMs, reason.error);
|
|
722
728
|
await new Promise((resolve) => {
|
|
723
729
|
setTimeout(resolve, delayMs);
|
|
724
730
|
});
|
|
@@ -727,9 +733,12 @@ export class ConnectionManager {
|
|
|
727
733
|
// NOTE: This isn't strictly true for drivers that don't require network (e.g. local driver). Really this logic
|
|
728
734
|
// should probably live in the driver.
|
|
729
735
|
await waitForOnline();
|
|
730
|
-
this.triggerConnect(
|
|
731
|
-
|
|
732
|
-
|
|
736
|
+
this.triggerConnect({
|
|
737
|
+
text: reason.error !== undefined
|
|
738
|
+
? "Reconnecting due to Error"
|
|
739
|
+
: `Reconnecting due to: ${reason.text}`,
|
|
740
|
+
error: reason.error,
|
|
741
|
+
}, requestedMode);
|
|
733
742
|
}
|
|
734
743
|
prepareMessageToSend(message) {
|
|
735
744
|
if (this.readonly === true) {
|
|
@@ -788,7 +797,7 @@ export class ConnectionManager {
|
|
|
788
797
|
if (this.pendingReconnect) {
|
|
789
798
|
// still valid?
|
|
790
799
|
await this.reconnect("write", // connectionMode
|
|
791
|
-
"Switch to write");
|
|
800
|
+
{ text: "Switch to write" });
|
|
792
801
|
}
|
|
793
802
|
})
|
|
794
803
|
.catch(() => { });
|
|
@@ -821,7 +830,7 @@ export class ConnectionManager {
|
|
|
821
830
|
// Clients need to be able to transition to "read" state after some time of inactivity!
|
|
822
831
|
// Note - this may close container!
|
|
823
832
|
this.reconnect("read", // connectionMode
|
|
824
|
-
"Switch to read").catch((error) => {
|
|
833
|
+
{ text: "Switch to read" }).catch((error) => {
|
|
825
834
|
this.logger.sendErrorEvent({ eventName: "SwitchToReadConnection" }, error);
|
|
826
835
|
});
|
|
827
836
|
}
|