@fluidframework/container-loader 2.0.0-internal.3.0.5 → 2.0.0-internal.3.1.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.
- package/.eslintrc.js +18 -21
- package/.mocharc.js +2 -2
- package/README.md +45 -43
- package/api-extractor.json +2 -2
- package/closeAndGetPendingLocalState.md +51 -0
- package/dist/audience.d.ts.map +1 -1
- package/dist/audience.js.map +1 -1
- package/dist/catchUpMonitor.d.ts.map +1 -1
- package/dist/catchUpMonitor.js.map +1 -1
- package/dist/collabWindowTracker.d.ts.map +1 -1
- package/dist/collabWindowTracker.js.map +1 -1
- package/dist/connectionManager.d.ts +2 -2
- package/dist/connectionManager.d.ts.map +1 -1
- package/dist/connectionManager.js +51 -24
- package/dist/connectionManager.js.map +1 -1
- package/dist/connectionState.d.ts.map +1 -1
- package/dist/connectionState.js.map +1 -1
- package/dist/connectionStateHandler.d.ts.map +1 -1
- package/dist/connectionStateHandler.js +35 -16
- package/dist/connectionStateHandler.js.map +1 -1
- package/dist/container.d.ts +1 -10
- package/dist/container.d.ts.map +1 -1
- package/dist/container.js +89 -44
- package/dist/container.js.map +1 -1
- package/dist/containerContext.d.ts.map +1 -1
- package/dist/containerContext.js +6 -2
- package/dist/containerContext.js.map +1 -1
- package/dist/containerStorageAdapter.d.ts.map +1 -1
- package/dist/containerStorageAdapter.js +2 -4
- package/dist/containerStorageAdapter.js.map +1 -1
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js.map +1 -1
- package/dist/deltaManager.d.ts +3 -3
- package/dist/deltaManager.d.ts.map +1 -1
- package/dist/deltaManager.js +56 -27
- package/dist/deltaManager.js.map +1 -1
- package/dist/deltaManagerProxy.d.ts.map +1 -1
- package/dist/deltaManagerProxy.js.map +1 -1
- package/dist/deltaQueue.d.ts.map +1 -1
- package/dist/deltaQueue.js +4 -2
- package/dist/deltaQueue.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/loader.d.ts +3 -3
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +18 -15
- package/dist/loader.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.map +1 -1
- package/dist/protocol.js +2 -1
- package/dist/protocol.js.map +1 -1
- package/dist/protocolTreeDocumentStorageService.d.ts.map +1 -1
- package/dist/protocolTreeDocumentStorageService.js.map +1 -1
- package/dist/quorum.d.ts.map +1 -1
- package/dist/quorum.js.map +1 -1
- package/dist/retriableDocumentStorageService.d.ts.map +1 -1
- package/dist/retriableDocumentStorageService.js +6 -2
- package/dist/retriableDocumentStorageService.js.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +6 -4
- package/dist/utils.js.map +1 -1
- package/lib/audience.d.ts.map +1 -1
- package/lib/audience.js.map +1 -1
- package/lib/catchUpMonitor.d.ts.map +1 -1
- package/lib/catchUpMonitor.js.map +1 -1
- package/lib/collabWindowTracker.d.ts.map +1 -1
- package/lib/collabWindowTracker.js.map +1 -1
- package/lib/connectionManager.d.ts +2 -2
- package/lib/connectionManager.d.ts.map +1 -1
- package/lib/connectionManager.js +53 -26
- package/lib/connectionManager.js.map +1 -1
- package/lib/connectionState.d.ts.map +1 -1
- package/lib/connectionState.js.map +1 -1
- package/lib/connectionStateHandler.d.ts.map +1 -1
- package/lib/connectionStateHandler.js +35 -16
- package/lib/connectionStateHandler.js.map +1 -1
- package/lib/container.d.ts +1 -10
- package/lib/container.d.ts.map +1 -1
- package/lib/container.js +93 -48
- package/lib/container.js.map +1 -1
- package/lib/containerContext.d.ts.map +1 -1
- package/lib/containerContext.js +6 -2
- package/lib/containerContext.js.map +1 -1
- package/lib/containerStorageAdapter.d.ts.map +1 -1
- package/lib/containerStorageAdapter.js +2 -4
- package/lib/containerStorageAdapter.js.map +1 -1
- package/lib/contracts.d.ts.map +1 -1
- package/lib/contracts.js.map +1 -1
- package/lib/deltaManager.d.ts +3 -3
- package/lib/deltaManager.d.ts.map +1 -1
- package/lib/deltaManager.js +58 -29
- package/lib/deltaManager.js.map +1 -1
- package/lib/deltaManagerProxy.d.ts.map +1 -1
- package/lib/deltaManagerProxy.js.map +1 -1
- package/lib/deltaQueue.d.ts.map +1 -1
- package/lib/deltaQueue.js +4 -2
- package/lib/deltaQueue.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/loader.d.ts +3 -3
- package/lib/loader.d.ts.map +1 -1
- package/lib/loader.js +18 -15
- package/lib/loader.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.map +1 -1
- package/lib/protocol.js +2 -1
- package/lib/protocol.js.map +1 -1
- package/lib/protocolTreeDocumentStorageService.d.ts.map +1 -1
- package/lib/protocolTreeDocumentStorageService.js.map +1 -1
- package/lib/quorum.d.ts.map +1 -1
- package/lib/quorum.js.map +1 -1
- package/lib/retriableDocumentStorageService.d.ts.map +1 -1
- package/lib/retriableDocumentStorageService.js +6 -2
- package/lib/retriableDocumentStorageService.js.map +1 -1
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +6 -4
- package/lib/utils.js.map +1 -1
- package/package.json +115 -114
- package/prettier.config.cjs +1 -1
- package/src/audience.ts +51 -46
- package/src/catchUpMonitor.ts +39 -37
- package/src/collabWindowTracker.ts +75 -70
- package/src/connectionManager.ts +1006 -944
- package/src/connectionState.ts +19 -19
- package/src/connectionStateHandler.ts +544 -465
- package/src/container.ts +2056 -1909
- package/src/containerContext.ts +350 -340
- package/src/containerStorageAdapter.ts +163 -153
- package/src/contracts.ts +155 -153
- package/src/deltaManager.ts +1069 -992
- package/src/deltaManagerProxy.ts +143 -137
- package/src/deltaQueue.ts +155 -151
- package/src/index.ts +14 -17
- package/src/loader.ts +428 -430
- package/src/packageVersion.ts +1 -1
- package/src/protocol.ts +93 -87
- package/src/protocolTreeDocumentStorageService.ts +30 -33
- package/src/quorum.ts +34 -34
- package/src/retriableDocumentStorageService.ts +118 -102
- package/src/utils.ts +89 -82
- package/tsconfig.esnext.json +6 -6
- package/tsconfig.json +8 -12
package/src/container.ts
CHANGED
|
@@ -7,87 +7,79 @@
|
|
|
7
7
|
import merge from "lodash/merge";
|
|
8
8
|
import { v4 as uuid } from "uuid";
|
|
9
9
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
ITelemetryBaseLogger,
|
|
11
|
+
ITelemetryLogger,
|
|
12
|
+
ITelemetryProperties,
|
|
13
|
+
TelemetryEventCategory,
|
|
14
14
|
} from "@fluidframework/common-definitions";
|
|
15
15
|
import { assert, performance, unreachableCase } from "@fluidframework/common-utils";
|
|
16
|
+
import { IRequest, IResponse, IFluidRouter } from "@fluidframework/core-interfaces";
|
|
16
17
|
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
IThrottlingWarning,
|
|
32
|
-
ReadOnlyInfo,
|
|
33
|
-
IContainerLoadMode,
|
|
34
|
-
IFluidCodeDetails,
|
|
35
|
-
isFluidCodeDetails,
|
|
36
|
-
IBatchMessage,
|
|
18
|
+
IAudience,
|
|
19
|
+
IConnectionDetails,
|
|
20
|
+
IContainer,
|
|
21
|
+
IContainerEvents,
|
|
22
|
+
IDeltaManager,
|
|
23
|
+
ICriticalContainerError,
|
|
24
|
+
ContainerWarning,
|
|
25
|
+
AttachState,
|
|
26
|
+
IThrottlingWarning,
|
|
27
|
+
ReadOnlyInfo,
|
|
28
|
+
IContainerLoadMode,
|
|
29
|
+
IFluidCodeDetails,
|
|
30
|
+
isFluidCodeDetails,
|
|
31
|
+
IBatchMessage,
|
|
37
32
|
} from "@fluidframework/container-definitions";
|
|
33
|
+
import { GenericError, UsageError } from "@fluidframework/container-utils";
|
|
38
34
|
import {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
IDocumentService,
|
|
44
|
-
IDocumentStorageService,
|
|
45
|
-
IFluidResolvedUrl,
|
|
46
|
-
IResolvedUrl,
|
|
35
|
+
IDocumentService,
|
|
36
|
+
IDocumentStorageService,
|
|
37
|
+
IFluidResolvedUrl,
|
|
38
|
+
IResolvedUrl,
|
|
47
39
|
} from "@fluidframework/driver-definitions";
|
|
48
40
|
import {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
41
|
+
readAndParse,
|
|
42
|
+
OnlineStatus,
|
|
43
|
+
isOnline,
|
|
44
|
+
ensureFluidResolvedUrl,
|
|
45
|
+
combineAppAndProtocolSummary,
|
|
46
|
+
runWithRetry,
|
|
47
|
+
isFluidResolvedUrl,
|
|
56
48
|
} from "@fluidframework/driver-utils";
|
|
57
49
|
import { IQuorumSnapshot } from "@fluidframework/protocol-base";
|
|
58
50
|
import {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
51
|
+
IClient,
|
|
52
|
+
IClientConfiguration,
|
|
53
|
+
IClientDetails,
|
|
54
|
+
ICommittedProposal,
|
|
55
|
+
IDocumentAttributes,
|
|
56
|
+
IDocumentMessage,
|
|
57
|
+
IProtocolState,
|
|
58
|
+
IQuorumClients,
|
|
59
|
+
IQuorumProposals,
|
|
60
|
+
ISequencedClient,
|
|
61
|
+
ISequencedDocumentMessage,
|
|
62
|
+
ISequencedProposal,
|
|
63
|
+
ISignalMessage,
|
|
64
|
+
ISnapshotTree,
|
|
65
|
+
ISummaryContent,
|
|
66
|
+
ISummaryTree,
|
|
67
|
+
IVersion,
|
|
68
|
+
MessageType,
|
|
69
|
+
SummaryType,
|
|
78
70
|
} from "@fluidframework/protocol-definitions";
|
|
79
71
|
import {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
72
|
+
ChildLogger,
|
|
73
|
+
EventEmitterWithErrorHandling,
|
|
74
|
+
PerformanceEvent,
|
|
75
|
+
raiseConnectedEvent,
|
|
76
|
+
TelemetryLogger,
|
|
77
|
+
connectedEventName,
|
|
78
|
+
disconnectedEventName,
|
|
79
|
+
normalizeError,
|
|
80
|
+
MonitoringContext,
|
|
81
|
+
loggerToMonitoringContext,
|
|
82
|
+
wrapError,
|
|
91
83
|
} from "@fluidframework/telemetry-utils";
|
|
92
84
|
import { Audience } from "./audience";
|
|
93
85
|
import { ContainerContext } from "./containerContext";
|
|
@@ -97,20 +89,17 @@ import { DeltaManagerProxy } from "./deltaManagerProxy";
|
|
|
97
89
|
import { ILoaderOptions, Loader, RelativeLoader } from "./loader";
|
|
98
90
|
import { pkgVersion } from "./packageVersion";
|
|
99
91
|
import { ContainerStorageAdapter } from "./containerStorageAdapter";
|
|
100
|
-
import {
|
|
101
|
-
IConnectionStateHandler,
|
|
102
|
-
createConnectionStateHandler,
|
|
103
|
-
} from "./connectionStateHandler";
|
|
92
|
+
import { IConnectionStateHandler, createConnectionStateHandler } from "./connectionStateHandler";
|
|
104
93
|
import { getProtocolSnapshotTree, getSnapshotTreeFromSerializedContainer } from "./utils";
|
|
105
|
-
import {
|
|
94
|
+
import {
|
|
95
|
+
initQuorumValuesFromCodeDetails,
|
|
96
|
+
getCodeDetailsFromQuorumValues,
|
|
97
|
+
QuorumProxy,
|
|
98
|
+
} from "./quorum";
|
|
106
99
|
import { CollabWindowTracker } from "./collabWindowTracker";
|
|
107
100
|
import { ConnectionManager } from "./connectionManager";
|
|
108
101
|
import { ConnectionState } from "./connectionState";
|
|
109
|
-
import {
|
|
110
|
-
IProtocolHandler,
|
|
111
|
-
ProtocolHandler,
|
|
112
|
-
ProtocolHandlerBuilder,
|
|
113
|
-
} from "./protocol";
|
|
102
|
+
import { IProtocolHandler, ProtocolHandler, ProtocolHandlerBuilder } from "./protocol";
|
|
114
103
|
|
|
115
104
|
const detachedContainerRefSeqNumber = 0;
|
|
116
105
|
|
|
@@ -118,54 +107,46 @@ const dirtyContainerEvent = "dirty";
|
|
|
118
107
|
const savedContainerEvent = "saved";
|
|
119
108
|
|
|
120
109
|
export interface IContainerLoadOptions {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* A scope object to replace the one provided on the Loader.
|
|
145
|
-
*/
|
|
146
|
-
scopeOverride?: FluidObject;
|
|
110
|
+
/**
|
|
111
|
+
* Disables the Container from reconnecting if false, allows reconnect otherwise.
|
|
112
|
+
*/
|
|
113
|
+
canReconnect?: boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Client details provided in the override will be merged over the default client.
|
|
116
|
+
*/
|
|
117
|
+
clientDetailsOverride?: IClientDetails;
|
|
118
|
+
resolvedUrl: IFluidResolvedUrl;
|
|
119
|
+
/**
|
|
120
|
+
* Control which snapshot version to load from. See IParsedUrl for detailed information.
|
|
121
|
+
*/
|
|
122
|
+
version: string | undefined;
|
|
123
|
+
/**
|
|
124
|
+
* Loads the Container in paused state if true, unpaused otherwise.
|
|
125
|
+
*/
|
|
126
|
+
loadMode?: IContainerLoadMode;
|
|
127
|
+
/**
|
|
128
|
+
* A logger that the container will use for logging operations. If not provided, the container will
|
|
129
|
+
* use the loader's logger, `Loader.services.subLogger`.
|
|
130
|
+
*/
|
|
131
|
+
baseLogger?: ITelemetryBaseLogger;
|
|
147
132
|
}
|
|
148
133
|
|
|
149
134
|
export interface IContainerConfig {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* A scope object to replace the one provided on the Loader.
|
|
167
|
-
*/
|
|
168
|
-
scopeOverride?: FluidObject;
|
|
135
|
+
resolvedUrl?: IFluidResolvedUrl;
|
|
136
|
+
canReconnect?: boolean;
|
|
137
|
+
/**
|
|
138
|
+
* Client details provided in the override will be merged over the default client.
|
|
139
|
+
*/
|
|
140
|
+
clientDetailsOverride?: IClientDetails;
|
|
141
|
+
/**
|
|
142
|
+
* Serialized state from a previous instance of this container
|
|
143
|
+
*/
|
|
144
|
+
serializedContainerState?: IPendingContainerState;
|
|
145
|
+
/**
|
|
146
|
+
* A logger that the container will use for logging operations. If not provided, the container will
|
|
147
|
+
* use the loader's logger, `Loader.services.subLogger`.
|
|
148
|
+
*/
|
|
149
|
+
baseLogger?: ITelemetryBaseLogger;
|
|
169
150
|
}
|
|
170
151
|
|
|
171
152
|
/**
|
|
@@ -185,77 +166,84 @@ export interface IContainerConfig {
|
|
|
185
166
|
* @throws an error beginning with `"Container closed"` if the container is closed before it catches up.
|
|
186
167
|
*/
|
|
187
168
|
export async function waitContainerToCatchUp(container: IContainer) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
169
|
+
// Make sure we stop waiting if container is closed.
|
|
170
|
+
if (container.closed) {
|
|
171
|
+
throw new UsageError("waitContainerToCatchUp: Container closed");
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return new Promise<boolean>((resolve, reject) => {
|
|
175
|
+
const deltaManager = container.deltaManager;
|
|
176
|
+
|
|
177
|
+
const closedCallback = (err?: ICriticalContainerError | undefined) => {
|
|
178
|
+
container.off("closed", closedCallback);
|
|
179
|
+
const baseMessage = "Container closed while waiting to catch up";
|
|
180
|
+
reject(
|
|
181
|
+
err !== undefined
|
|
182
|
+
? wrapError(
|
|
183
|
+
err,
|
|
184
|
+
(innerMessage) => new GenericError(`${baseMessage}: ${innerMessage}`),
|
|
185
|
+
)
|
|
186
|
+
: new GenericError(baseMessage),
|
|
187
|
+
);
|
|
188
|
+
};
|
|
189
|
+
container.on("closed", closedCallback);
|
|
190
|
+
|
|
191
|
+
// Depending on config, transition to "connected" state may include the guarantee
|
|
192
|
+
// that all known ops have been processed. If so, we may introduce additional wait here.
|
|
193
|
+
// Waiting for "connected" state in either case gets us at least to our own Join op
|
|
194
|
+
// which is a reasonable approximation of "caught up"
|
|
195
|
+
const waitForOps = () => {
|
|
196
|
+
assert(
|
|
197
|
+
container.connectionState === ConnectionState.CatchingUp ||
|
|
198
|
+
container.connectionState === ConnectionState.Connected,
|
|
199
|
+
0x0cd /* "Container disconnected while waiting for ops!" */,
|
|
200
|
+
);
|
|
201
|
+
const hasCheckpointSequenceNumber = deltaManager.hasCheckpointSequenceNumber;
|
|
202
|
+
|
|
203
|
+
const connectionOpSeqNumber = deltaManager.lastKnownSeqNumber;
|
|
204
|
+
assert(
|
|
205
|
+
deltaManager.lastSequenceNumber <= connectionOpSeqNumber,
|
|
206
|
+
0x266 /* "lastKnownSeqNumber should never be below last processed sequence number" */,
|
|
207
|
+
);
|
|
208
|
+
if (deltaManager.lastSequenceNumber === connectionOpSeqNumber) {
|
|
209
|
+
container.off("closed", closedCallback);
|
|
210
|
+
resolve(hasCheckpointSequenceNumber);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const callbackOps = (message: ISequencedDocumentMessage) => {
|
|
214
|
+
if (connectionOpSeqNumber <= message.sequenceNumber) {
|
|
215
|
+
container.off("closed", closedCallback);
|
|
216
|
+
resolve(hasCheckpointSequenceNumber);
|
|
217
|
+
deltaManager.off("op", callbackOps);
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
deltaManager.on("op", callbackOps);
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
// We can leverage DeltaManager's "connect" event here and test for ConnectionState.Disconnected
|
|
224
|
+
// But that works only if service provides us checkPointSequenceNumber
|
|
225
|
+
// Our internal testing is based on R11S that does not, but almost all tests connect as "write" and
|
|
226
|
+
// use this function to catch up, so leveraging our own join op as a fence/barrier
|
|
227
|
+
if (container.connectionState === ConnectionState.Connected) {
|
|
228
|
+
waitForOps();
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const callback = () => {
|
|
233
|
+
container.off(connectedEventName, callback);
|
|
234
|
+
waitForOps();
|
|
235
|
+
};
|
|
236
|
+
container.on(connectedEventName, callback);
|
|
237
|
+
|
|
238
|
+
if (container.connectionState === ConnectionState.Disconnected) {
|
|
239
|
+
container.connect();
|
|
240
|
+
}
|
|
241
|
+
});
|
|
254
242
|
}
|
|
255
243
|
|
|
256
244
|
const getCodeProposal =
|
|
257
|
-
|
|
258
|
-
|
|
245
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
246
|
+
(quorum: IQuorumProposals) => quorum.get("code") ?? quorum.get("code2");
|
|
259
247
|
|
|
260
248
|
/**
|
|
261
249
|
* Helper function to report to telemetry cases where operation takes longer than expected (200ms)
|
|
@@ -264,15 +252,15 @@ const getCodeProposal =
|
|
|
264
252
|
* @param action - functor to call and measure
|
|
265
253
|
*/
|
|
266
254
|
export async function ReportIfTooLong(
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
255
|
+
logger: ITelemetryLogger,
|
|
256
|
+
eventName: string,
|
|
257
|
+
action: () => Promise<ITelemetryProperties>,
|
|
270
258
|
) {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
259
|
+
const event = PerformanceEvent.start(logger, { eventName });
|
|
260
|
+
const props = await action();
|
|
261
|
+
if (event.duration > 200) {
|
|
262
|
+
event.end(props);
|
|
263
|
+
}
|
|
276
264
|
}
|
|
277
265
|
|
|
278
266
|
/**
|
|
@@ -280,1717 +268,1876 @@ export async function ReportIfTooLong(
|
|
|
280
268
|
* of the container to the same state
|
|
281
269
|
*/
|
|
282
270
|
export interface IPendingContainerState {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
271
|
+
pendingRuntimeState: unknown;
|
|
272
|
+
url: string;
|
|
273
|
+
protocol: IProtocolState;
|
|
274
|
+
term: number;
|
|
275
|
+
clientId?: string;
|
|
288
276
|
}
|
|
289
277
|
|
|
290
278
|
const summarizerClientType = "summarizer";
|
|
291
279
|
|
|
292
|
-
export class Container
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
280
|
+
export class Container
|
|
281
|
+
extends EventEmitterWithErrorHandling<IContainerEvents>
|
|
282
|
+
implements IContainer
|
|
283
|
+
{
|
|
284
|
+
public static version = "^0.1.0";
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Load an existing container.
|
|
288
|
+
*/
|
|
289
|
+
public static async load(
|
|
290
|
+
loader: Loader,
|
|
291
|
+
loadOptions: IContainerLoadOptions,
|
|
292
|
+
pendingLocalState?: IPendingContainerState,
|
|
293
|
+
protocolHandlerBuilder?: ProtocolHandlerBuilder,
|
|
294
|
+
): Promise<Container> {
|
|
295
|
+
const container = new Container(
|
|
296
|
+
loader,
|
|
297
|
+
{
|
|
298
|
+
clientDetailsOverride: loadOptions.clientDetailsOverride,
|
|
299
|
+
resolvedUrl: loadOptions.resolvedUrl,
|
|
300
|
+
canReconnect: loadOptions.canReconnect,
|
|
301
|
+
serializedContainerState: pendingLocalState,
|
|
302
|
+
baseLogger: loadOptions.baseLogger,
|
|
303
|
+
},
|
|
304
|
+
protocolHandlerBuilder,
|
|
305
|
+
);
|
|
306
|
+
|
|
307
|
+
return PerformanceEvent.timedExecAsync(
|
|
308
|
+
container.mc.logger,
|
|
309
|
+
{ eventName: "Load" },
|
|
310
|
+
async (event) =>
|
|
311
|
+
new Promise<Container>((resolve, reject) => {
|
|
312
|
+
const version = loadOptions.version;
|
|
313
|
+
|
|
314
|
+
const defaultMode: IContainerLoadMode = { opsBeforeReturn: "cached" };
|
|
315
|
+
// if we have pendingLocalState, anything we cached is not useful and we shouldn't wait for connection
|
|
316
|
+
// to return container, so ignore this value and use undefined for opsBeforeReturn
|
|
317
|
+
const mode: IContainerLoadMode = pendingLocalState
|
|
318
|
+
? { ...(loadOptions.loadMode ?? defaultMode), opsBeforeReturn: undefined }
|
|
319
|
+
: loadOptions.loadMode ?? defaultMode;
|
|
320
|
+
|
|
321
|
+
const onClosed = (err?: ICriticalContainerError) => {
|
|
322
|
+
// pre-0.58 error message: containerClosedWithoutErrorDuringLoad
|
|
323
|
+
reject(
|
|
324
|
+
err ?? new GenericError("Container closed without error during load"),
|
|
325
|
+
);
|
|
326
|
+
};
|
|
327
|
+
container.on("closed", onClosed);
|
|
328
|
+
|
|
329
|
+
container
|
|
330
|
+
.load(version, mode, pendingLocalState)
|
|
331
|
+
.finally(() => {
|
|
332
|
+
container.removeListener("closed", onClosed);
|
|
333
|
+
})
|
|
334
|
+
.then(
|
|
335
|
+
(props) => {
|
|
336
|
+
event.end({ ...props, ...loadOptions.loadMode });
|
|
337
|
+
resolve(container);
|
|
338
|
+
},
|
|
339
|
+
(error) => {
|
|
340
|
+
const err = normalizeError(error);
|
|
341
|
+
// Depending where error happens, we can be attempting to connect to web socket
|
|
342
|
+
// and continuously retrying (consider offline mode)
|
|
343
|
+
// Host has no container to close, so it's prudent to do it here
|
|
344
|
+
container.close(err);
|
|
345
|
+
onClosed(err);
|
|
346
|
+
},
|
|
347
|
+
);
|
|
348
|
+
}),
|
|
349
|
+
{ start: true, end: true, cancel: "generic" },
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Create a new container in a detached state.
|
|
355
|
+
*/
|
|
356
|
+
public static async createDetached(
|
|
357
|
+
loader: Loader,
|
|
358
|
+
codeDetails: IFluidCodeDetails,
|
|
359
|
+
protocolHandlerBuilder?: ProtocolHandlerBuilder,
|
|
360
|
+
): Promise<Container> {
|
|
361
|
+
const container = new Container(loader, {}, protocolHandlerBuilder);
|
|
362
|
+
|
|
363
|
+
return PerformanceEvent.timedExecAsync(
|
|
364
|
+
container.mc.logger,
|
|
365
|
+
{ eventName: "CreateDetached" },
|
|
366
|
+
async (_event) => {
|
|
367
|
+
await container.createDetached(codeDetails);
|
|
368
|
+
return container;
|
|
369
|
+
},
|
|
370
|
+
{ start: true, end: true, cancel: "generic" },
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Create a new container in a detached state that is initialized with a
|
|
376
|
+
* snapshot from a previous detached container.
|
|
377
|
+
*/
|
|
378
|
+
public static async rehydrateDetachedFromSnapshot(
|
|
379
|
+
loader: Loader,
|
|
380
|
+
snapshot: string,
|
|
381
|
+
protocolHandlerBuilder?: ProtocolHandlerBuilder,
|
|
382
|
+
): Promise<Container> {
|
|
383
|
+
const container = new Container(loader, {}, protocolHandlerBuilder);
|
|
384
|
+
|
|
385
|
+
return PerformanceEvent.timedExecAsync(
|
|
386
|
+
container.mc.logger,
|
|
387
|
+
{ eventName: "RehydrateDetachedFromSnapshot" },
|
|
388
|
+
async (_event) => {
|
|
389
|
+
const deserializedSummary = JSON.parse(snapshot) as ISummaryTree;
|
|
390
|
+
await container.rehydrateDetachedFromSnapshot(deserializedSummary);
|
|
391
|
+
return container;
|
|
392
|
+
},
|
|
393
|
+
{ start: true, end: true, cancel: "generic" },
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
public subLogger: TelemetryLogger;
|
|
398
|
+
|
|
399
|
+
// Tells if container can reconnect on losing fist connection
|
|
400
|
+
// If false, container gets closed on loss of connection.
|
|
401
|
+
private readonly _canReconnect: boolean = true;
|
|
402
|
+
|
|
403
|
+
private readonly mc: MonitoringContext;
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Lifecycle state of the container, used mainly to prevent re-entrancy and telemetry
|
|
407
|
+
*
|
|
408
|
+
* States are allowed to progress to further states:
|
|
409
|
+
* "loading" - "loaded" - "closing" - "disposing" - "closed" - "disposed"
|
|
410
|
+
*
|
|
411
|
+
* For example, moving from "closed" to "disposing" is not allowed since it is an earlier state.
|
|
412
|
+
*
|
|
413
|
+
* loading: Container has been created, but is not yet in normal/loaded state
|
|
414
|
+
* loaded: Container is in normal/loaded state
|
|
415
|
+
* closing: Container has started closing process (for re-entrancy prevention)
|
|
416
|
+
* disposing: Container has started disposing process (for re-entrancy prevention)
|
|
417
|
+
* closed: Container has closed
|
|
418
|
+
* disposed: Container has been disposed
|
|
419
|
+
*/
|
|
420
|
+
private _lifecycleState:
|
|
421
|
+
| "loading"
|
|
422
|
+
| "loaded"
|
|
423
|
+
| "closing"
|
|
424
|
+
| "disposing"
|
|
425
|
+
| "closed"
|
|
426
|
+
| "disposed" = "loading";
|
|
427
|
+
|
|
428
|
+
private setLoaded() {
|
|
429
|
+
// It's conceivable the container could be closed when this is called
|
|
430
|
+
// Only transition states if currently loading
|
|
431
|
+
if (this._lifecycleState === "loading") {
|
|
432
|
+
// Propagate current connection state through the system.
|
|
433
|
+
this.propagateConnectionState(true /* initial transition */);
|
|
434
|
+
this._lifecycleState = "loaded";
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
public get closed(): boolean {
|
|
439
|
+
return (
|
|
440
|
+
this._lifecycleState === "closing" ||
|
|
441
|
+
this._lifecycleState === "closed" ||
|
|
442
|
+
this._lifecycleState === "disposing" ||
|
|
443
|
+
this._lifecycleState === "disposed"
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
private _attachState = AttachState.Detached;
|
|
448
|
+
|
|
449
|
+
private readonly storageService: ContainerStorageAdapter;
|
|
450
|
+
public get storage(): IDocumentStorageService {
|
|
451
|
+
return this.storageService;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
private readonly clientDetailsOverride: IClientDetails | undefined;
|
|
455
|
+
private readonly _deltaManager: DeltaManager<ConnectionManager>;
|
|
456
|
+
private service: IDocumentService | undefined;
|
|
457
|
+
|
|
458
|
+
private _context: ContainerContext | undefined;
|
|
459
|
+
private get context() {
|
|
460
|
+
if (this._context === undefined) {
|
|
461
|
+
throw new GenericError("Attempted to access context before it was defined");
|
|
462
|
+
}
|
|
463
|
+
return this._context;
|
|
464
|
+
}
|
|
465
|
+
private _protocolHandler: IProtocolHandler | undefined;
|
|
466
|
+
private get protocolHandler() {
|
|
467
|
+
if (this._protocolHandler === undefined) {
|
|
468
|
+
throw new Error("Attempted to access protocolHandler before it was defined");
|
|
469
|
+
}
|
|
470
|
+
return this._protocolHandler;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/** During initialization we pause the inbound queues. We track this state to ensure we only call resume once */
|
|
474
|
+
private inboundQueuePausedFromInit = true;
|
|
475
|
+
private firstConnection = true;
|
|
476
|
+
private readonly connectionTransitionTimes: number[] = [];
|
|
477
|
+
private messageCountAfterDisconnection: number = 0;
|
|
478
|
+
private _loadedFromVersion: IVersion | undefined;
|
|
479
|
+
private _resolvedUrl: IFluidResolvedUrl | undefined;
|
|
480
|
+
private attachStarted = false;
|
|
481
|
+
private _dirtyContainer = false;
|
|
482
|
+
|
|
483
|
+
private lastVisible: number | undefined;
|
|
484
|
+
private readonly visibilityEventHandler: (() => void) | undefined;
|
|
485
|
+
private readonly connectionStateHandler: IConnectionStateHandler;
|
|
486
|
+
|
|
487
|
+
private setAutoReconnectTime = performance.now();
|
|
488
|
+
|
|
489
|
+
private collabWindowTracker: CollabWindowTracker | undefined;
|
|
490
|
+
|
|
491
|
+
private get connectionMode() {
|
|
492
|
+
return this._deltaManager.connectionManager.connectionMode;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
public get IFluidRouter(): IFluidRouter {
|
|
496
|
+
return this;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
public get resolvedUrl(): IResolvedUrl | undefined {
|
|
500
|
+
return this._resolvedUrl;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
public get loadedFromVersion(): IVersion | undefined {
|
|
504
|
+
return this._loadedFromVersion;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
public get readOnlyInfo(): ReadOnlyInfo {
|
|
508
|
+
return this._deltaManager.readOnlyInfo;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
public get closeSignal(): AbortSignal {
|
|
512
|
+
return this._deltaManager.closeAbortController.signal;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Tracks host requiring read-only mode.
|
|
517
|
+
*/
|
|
518
|
+
public forceReadonly(readonly: boolean) {
|
|
519
|
+
this._deltaManager.connectionManager.forceReadonly(readonly);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
public get deltaManager(): IDeltaManager<ISequencedDocumentMessage, IDocumentMessage> {
|
|
523
|
+
return this._deltaManager;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
public get connectionState(): ConnectionState {
|
|
527
|
+
return this.connectionStateHandler.connectionState;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
public get connected(): boolean {
|
|
531
|
+
return this.connectionStateHandler.connectionState === ConnectionState.Connected;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* Service configuration details. If running in offline mode will be undefined otherwise will contain service
|
|
536
|
+
* configuration details returned as part of the initial connection.
|
|
537
|
+
*/
|
|
538
|
+
public get serviceConfiguration(): IClientConfiguration | undefined {
|
|
539
|
+
return this._deltaManager.serviceConfiguration;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
private _clientId: string | undefined;
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* The server provided id of the client.
|
|
546
|
+
* Set once this.connected is true, otherwise undefined
|
|
547
|
+
*/
|
|
548
|
+
public get clientId(): string | undefined {
|
|
549
|
+
return this._clientId;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* The server provided claims of the client.
|
|
554
|
+
* Set once this.connected is true, otherwise undefined
|
|
555
|
+
*/
|
|
556
|
+
public get scopes(): string[] | undefined {
|
|
557
|
+
return this._deltaManager.connectionManager.scopes;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
public get clientDetails(): IClientDetails {
|
|
561
|
+
return this._deltaManager.clientDetails;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* Get the code details that are currently specified for the container.
|
|
566
|
+
* @returns The current code details if any are specified, undefined if none are specified.
|
|
567
|
+
*/
|
|
568
|
+
public getSpecifiedCodeDetails(): IFluidCodeDetails | undefined {
|
|
569
|
+
return this.getCodeDetailsFromQuorum();
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Get the code details that were used to load the container.
|
|
574
|
+
* @returns The code details that were used to load the container if it is loaded, undefined if it is not yet
|
|
575
|
+
* loaded.
|
|
576
|
+
*/
|
|
577
|
+
public getLoadedCodeDetails(): IFluidCodeDetails | undefined {
|
|
578
|
+
return this._context?.codeDetails;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* Retrieves the audience associated with the document
|
|
583
|
+
*/
|
|
584
|
+
public get audience(): IAudience {
|
|
585
|
+
return this.protocolHandler.audience;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Returns true if container is dirty.
|
|
590
|
+
* Which means data loss if container is closed at that same moment
|
|
591
|
+
* Most likely that happens when there is no network connection to Relay Service
|
|
592
|
+
*/
|
|
593
|
+
public get isDirty() {
|
|
594
|
+
return this._dirtyContainer;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
private get serviceFactory() {
|
|
598
|
+
return this.loader.services.documentServiceFactory;
|
|
599
|
+
}
|
|
600
|
+
private get urlResolver() {
|
|
601
|
+
return this.loader.services.urlResolver;
|
|
602
|
+
}
|
|
603
|
+
public readonly options: ILoaderOptions;
|
|
604
|
+
private get scope() {
|
|
605
|
+
return this.loader.services.scope;
|
|
606
|
+
}
|
|
607
|
+
private get codeLoader() {
|
|
608
|
+
return this.loader.services.codeLoader;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
constructor(
|
|
612
|
+
private readonly loader: Loader,
|
|
613
|
+
config: IContainerConfig,
|
|
614
|
+
private readonly protocolHandlerBuilder?: ProtocolHandlerBuilder,
|
|
615
|
+
) {
|
|
616
|
+
super((name, error) => {
|
|
617
|
+
this.mc.logger.sendErrorEvent(
|
|
618
|
+
{
|
|
619
|
+
eventName: "ContainerEventHandlerException",
|
|
620
|
+
name: typeof name === "string" ? name : undefined,
|
|
621
|
+
},
|
|
622
|
+
error,
|
|
623
|
+
);
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
this.clientDetailsOverride = config.clientDetailsOverride;
|
|
627
|
+
this._resolvedUrl = config.resolvedUrl;
|
|
628
|
+
if (config.canReconnect !== undefined) {
|
|
629
|
+
this._canReconnect = config.canReconnect;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
// Create logger for data stores to use
|
|
633
|
+
const type = this.client.details.type;
|
|
634
|
+
const interactive = this.client.details.capabilities.interactive;
|
|
635
|
+
const clientType = `${interactive ? "interactive" : "noninteractive"}${
|
|
636
|
+
type !== undefined && type !== "" ? `/${type}` : ""
|
|
637
|
+
}`;
|
|
638
|
+
// Need to use the property getter for docId because for detached flow we don't have the docId initially.
|
|
639
|
+
// We assign the id later so property getter is used.
|
|
640
|
+
this.subLogger = ChildLogger.create(
|
|
641
|
+
// If a baseLogger was provided, use it; otherwise use the loader's logger.
|
|
642
|
+
config.baseLogger ?? loader.services.subLogger,
|
|
643
|
+
undefined,
|
|
644
|
+
{
|
|
645
|
+
all: {
|
|
646
|
+
clientType, // Differentiating summarizer container from main container
|
|
647
|
+
containerId: uuid(),
|
|
648
|
+
docId: () => this._resolvedUrl?.id ?? undefined,
|
|
649
|
+
containerAttachState: () => this._attachState,
|
|
650
|
+
containerLifecycleState: () => this._lifecycleState,
|
|
651
|
+
containerConnectionState: () => ConnectionState[this.connectionState],
|
|
652
|
+
serializedContainer: config.serializedContainerState !== undefined,
|
|
653
|
+
},
|
|
654
|
+
// we need to be judicious with our logging here to avoid generating too much data
|
|
655
|
+
// all data logged here should be broadly applicable, and not specific to a
|
|
656
|
+
// specific error or class of errors
|
|
657
|
+
error: {
|
|
658
|
+
// load information to associate errors with the specific load point
|
|
659
|
+
dmInitialSeqNumber: () => this._deltaManager?.initialSequenceNumber,
|
|
660
|
+
dmLastProcessedSeqNumber: () => this._deltaManager?.lastSequenceNumber,
|
|
661
|
+
dmLastKnownSeqNumber: () => this._deltaManager?.lastKnownSeqNumber,
|
|
662
|
+
containerLoadedFromVersionId: () => this.loadedFromVersion?.id,
|
|
663
|
+
containerLoadedFromVersionDate: () => this.loadedFromVersion?.date,
|
|
664
|
+
// message information to associate errors with the specific execution state
|
|
665
|
+
// dmLastMsqSeqNumber: if present, same as dmLastProcessedSeqNumber
|
|
666
|
+
dmLastMsqSeqNumber: () => this.deltaManager?.lastMessage?.sequenceNumber,
|
|
667
|
+
dmLastMsqSeqTimestamp: () => this.deltaManager?.lastMessage?.timestamp,
|
|
668
|
+
dmLastMsqSeqClientId: () => this.deltaManager?.lastMessage?.clientId,
|
|
669
|
+
dmLastMsgClientSeq: () => this.deltaManager?.lastMessage?.clientSequenceNumber,
|
|
670
|
+
connectionStateDuration: () =>
|
|
671
|
+
performance.now() - this.connectionTransitionTimes[this.connectionState],
|
|
672
|
+
},
|
|
673
|
+
},
|
|
674
|
+
);
|
|
675
|
+
|
|
676
|
+
// Prefix all events in this file with container-loader
|
|
677
|
+
this.mc = loggerToMonitoringContext(ChildLogger.create(this.subLogger, "Container"));
|
|
678
|
+
|
|
679
|
+
const summarizeProtocolTree =
|
|
680
|
+
this.mc.config.getBoolean("Fluid.Container.summarizeProtocolTree2") ??
|
|
681
|
+
this.loader.services.options.summarizeProtocolTree;
|
|
682
|
+
|
|
683
|
+
this.options = {
|
|
684
|
+
...this.loader.services.options,
|
|
685
|
+
summarizeProtocolTree,
|
|
686
|
+
};
|
|
687
|
+
|
|
688
|
+
this._deltaManager = this.createDeltaManager();
|
|
689
|
+
|
|
690
|
+
this._clientId = config.serializedContainerState?.clientId;
|
|
691
|
+
this.connectionStateHandler = createConnectionStateHandler(
|
|
692
|
+
{
|
|
693
|
+
logger: this.mc.logger,
|
|
694
|
+
connectionStateChanged: (value, oldState, reason) => {
|
|
695
|
+
if (value === ConnectionState.Connected) {
|
|
696
|
+
this._clientId = this.connectionStateHandler.pendingClientId;
|
|
697
|
+
}
|
|
698
|
+
this.logConnectionStateChangeTelemetry(value, oldState, reason);
|
|
699
|
+
if (this._lifecycleState === "loaded") {
|
|
700
|
+
this.propagateConnectionState(
|
|
701
|
+
false /* initial transition */,
|
|
702
|
+
value === ConnectionState.Disconnected
|
|
703
|
+
? reason
|
|
704
|
+
: undefined /* disconnectedReason */,
|
|
705
|
+
);
|
|
706
|
+
}
|
|
707
|
+
},
|
|
708
|
+
shouldClientJoinWrite: () => this._deltaManager.connectionManager.shouldJoinWrite(),
|
|
709
|
+
maxClientLeaveWaitTime: this.loader.services.options.maxClientLeaveWaitTime,
|
|
710
|
+
logConnectionIssue: (
|
|
711
|
+
eventName: string,
|
|
712
|
+
category: TelemetryEventCategory,
|
|
713
|
+
details?: ITelemetryProperties,
|
|
714
|
+
) => {
|
|
715
|
+
const mode = this.connectionMode;
|
|
716
|
+
// We get here when socket does not receive any ops on "write" connection, including
|
|
717
|
+
// its own join op.
|
|
718
|
+
// Report issues only if we already loaded container - op processing is paused while container is loading,
|
|
719
|
+
// so we always time-out processing of join op in cases where fetching snapshot takes a minute.
|
|
720
|
+
// It's not a problem with op processing itself - such issues should be tracked as part of boot perf monitoring instead.
|
|
721
|
+
this._deltaManager.logConnectionIssue({
|
|
722
|
+
eventName,
|
|
723
|
+
mode,
|
|
724
|
+
category: this._lifecycleState === "loading" ? "generic" : category,
|
|
725
|
+
duration:
|
|
726
|
+
performance.now() -
|
|
727
|
+
this.connectionTransitionTimes[ConnectionState.CatchingUp],
|
|
728
|
+
...(details === undefined ? {} : { details: JSON.stringify(details) }),
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
// If this is "write" connection, it took too long to receive join op. But in most cases that's due
|
|
732
|
+
// to very slow op fetches and we will eventually get there.
|
|
733
|
+
// For "read" connections, we get here due to self join signal not arriving on time. We will need to
|
|
734
|
+
// better understand when and why it may happen.
|
|
735
|
+
// For now, attempt to recover by reconnecting. In future, maybe we can query relay service for
|
|
736
|
+
// current state of audience.
|
|
737
|
+
// Other possible recovery path - move to connected state (i.e. ConnectionStateHandler.joinOpTimer
|
|
738
|
+
// to call this.applyForConnectedState("addMemberEvent") for "read" connections)
|
|
739
|
+
if (mode === "read") {
|
|
740
|
+
this.disconnect();
|
|
741
|
+
this.connect();
|
|
742
|
+
}
|
|
743
|
+
},
|
|
744
|
+
},
|
|
745
|
+
this.deltaManager,
|
|
746
|
+
this._clientId,
|
|
747
|
+
);
|
|
748
|
+
|
|
749
|
+
this.on(savedContainerEvent, () => {
|
|
750
|
+
this.connectionStateHandler.containerSaved();
|
|
751
|
+
});
|
|
752
|
+
|
|
753
|
+
this.storageService = new ContainerStorageAdapter(
|
|
754
|
+
this.loader.services.detachedBlobStorage,
|
|
755
|
+
this.mc.logger,
|
|
756
|
+
this.options.summarizeProtocolTree === true
|
|
757
|
+
? () => this.captureProtocolSummary()
|
|
758
|
+
: undefined,
|
|
759
|
+
);
|
|
760
|
+
|
|
761
|
+
const isDomAvailable =
|
|
762
|
+
typeof document === "object" &&
|
|
763
|
+
document !== null &&
|
|
764
|
+
typeof document.addEventListener === "function" &&
|
|
765
|
+
document.addEventListener !== null;
|
|
766
|
+
// keep track of last time page was visible for telemetry
|
|
767
|
+
if (isDomAvailable) {
|
|
768
|
+
this.lastVisible = document.hidden ? performance.now() : undefined;
|
|
769
|
+
this.visibilityEventHandler = () => {
|
|
770
|
+
if (document.hidden) {
|
|
771
|
+
this.lastVisible = performance.now();
|
|
772
|
+
} else {
|
|
773
|
+
// settimeout so this will hopefully fire after disconnect event if being hidden caused it
|
|
774
|
+
setTimeout(() => {
|
|
775
|
+
this.lastVisible = undefined;
|
|
776
|
+
}, 0);
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
document.addEventListener("visibilitychange", this.visibilityEventHandler);
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
// We observed that most users of platform do not check Container.connected event on load, causing bugs.
|
|
783
|
+
// As such, we are raising events when new listener pops up.
|
|
784
|
+
// Note that we can raise both "disconnected" & "connect" events at the same time,
|
|
785
|
+
// if we are in connecting stage.
|
|
786
|
+
this.on("newListener", (event: string, listener: (...args: any[]) => void) => {
|
|
787
|
+
// Fire events on the end of JS turn, giving a chance for caller to be in consistent state.
|
|
788
|
+
Promise.resolve()
|
|
789
|
+
.then(() => {
|
|
790
|
+
switch (event) {
|
|
791
|
+
case dirtyContainerEvent:
|
|
792
|
+
if (this._dirtyContainer) {
|
|
793
|
+
listener();
|
|
794
|
+
}
|
|
795
|
+
break;
|
|
796
|
+
case savedContainerEvent:
|
|
797
|
+
if (!this._dirtyContainer) {
|
|
798
|
+
listener();
|
|
799
|
+
}
|
|
800
|
+
break;
|
|
801
|
+
case connectedEventName:
|
|
802
|
+
if (this.connected) {
|
|
803
|
+
listener(this.clientId);
|
|
804
|
+
}
|
|
805
|
+
break;
|
|
806
|
+
case disconnectedEventName:
|
|
807
|
+
if (!this.connected) {
|
|
808
|
+
listener();
|
|
809
|
+
}
|
|
810
|
+
break;
|
|
811
|
+
default:
|
|
812
|
+
}
|
|
813
|
+
})
|
|
814
|
+
.catch((error) => {
|
|
815
|
+
this.mc.logger.sendErrorEvent({ eventName: "RaiseConnectedEventError" }, error);
|
|
816
|
+
});
|
|
817
|
+
});
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* Retrieves the quorum associated with the document
|
|
822
|
+
*/
|
|
823
|
+
public getQuorum(): IQuorumClients {
|
|
824
|
+
return this.protocolHandler.quorum;
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
public dispose?(error?: ICriticalContainerError) {
|
|
828
|
+
this._deltaManager.close(error, true /* doDispose */);
|
|
829
|
+
this.verifyClosed();
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
public close(error?: ICriticalContainerError) {
|
|
833
|
+
// 1. Ensure that close sequence is exactly the same no matter if it's initiated by host or by DeltaManager
|
|
834
|
+
// 2. We need to ensure that we deliver disconnect event to runtime properly. See connectionStateChanged
|
|
835
|
+
// handler. We only deliver events if container fully loaded. Transitioning from "loading" ->
|
|
836
|
+
// "closing" will lose that info (can also solve by tracking extra state).
|
|
837
|
+
this._deltaManager.close(error);
|
|
838
|
+
this.verifyClosed();
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
private verifyClosed(): void {
|
|
842
|
+
assert(
|
|
843
|
+
this.connectionState === ConnectionState.Disconnected,
|
|
844
|
+
0x0cf /* "disconnect event was not raised!" */,
|
|
845
|
+
);
|
|
846
|
+
|
|
847
|
+
assert(
|
|
848
|
+
this._lifecycleState === "closed" || this._lifecycleState === "disposed",
|
|
849
|
+
0x314 /* Container properly closed */,
|
|
850
|
+
);
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
private closeCore(error?: ICriticalContainerError) {
|
|
854
|
+
assert(!this.closed, 0x315 /* re-entrancy */);
|
|
855
|
+
|
|
856
|
+
try {
|
|
857
|
+
// Ensure that we raise all key events even if one of these throws
|
|
858
|
+
try {
|
|
859
|
+
// Raise event first, to ensure we capture _lifecycleState before transition.
|
|
860
|
+
// This gives us a chance to know what errors happened on open vs. on fully loaded container.
|
|
861
|
+
this.mc.logger.sendTelemetryEvent(
|
|
862
|
+
{
|
|
863
|
+
eventName: "ContainerClose",
|
|
864
|
+
category: error === undefined ? "generic" : "error",
|
|
865
|
+
},
|
|
866
|
+
error,
|
|
867
|
+
);
|
|
868
|
+
|
|
869
|
+
this._lifecycleState = "closing";
|
|
870
|
+
|
|
871
|
+
this._protocolHandler?.close();
|
|
872
|
+
|
|
873
|
+
this.connectionStateHandler.dispose();
|
|
874
|
+
|
|
875
|
+
this._context?.dispose(error !== undefined ? new Error(error.message) : undefined);
|
|
876
|
+
|
|
877
|
+
this.storageService.dispose();
|
|
878
|
+
|
|
879
|
+
// Notify storage about critical errors. They may be due to disconnect between client & server knowledge
|
|
880
|
+
// about file, like file being overwritten in storage, but client having stale local cache.
|
|
881
|
+
// Driver need to ensure all caches are cleared on critical errors
|
|
882
|
+
this.service?.dispose(error);
|
|
883
|
+
} catch (exception) {
|
|
884
|
+
this.mc.logger.sendErrorEvent({ eventName: "ContainerCloseException" }, exception);
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
this.emit("closed", error);
|
|
888
|
+
|
|
889
|
+
if (this.visibilityEventHandler !== undefined) {
|
|
890
|
+
document.removeEventListener("visibilitychange", this.visibilityEventHandler);
|
|
891
|
+
}
|
|
892
|
+
} finally {
|
|
893
|
+
this._lifecycleState = "closed";
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
private _disposed = false;
|
|
898
|
+
private disposeCore(error?: ICriticalContainerError) {
|
|
899
|
+
assert(!this._disposed, 0x54c /* Container already disposed */);
|
|
900
|
+
this._disposed = true;
|
|
901
|
+
|
|
902
|
+
try {
|
|
903
|
+
// Ensure that we raise all key events even if one of these throws
|
|
904
|
+
try {
|
|
905
|
+
// Raise event first, to ensure we capture _lifecycleState before transition.
|
|
906
|
+
// This gives us a chance to know what errors happened on open vs. on fully loaded container.
|
|
907
|
+
this.mc.logger.sendTelemetryEvent(
|
|
908
|
+
{
|
|
909
|
+
eventName: "ContainerDispose",
|
|
910
|
+
category: "generic",
|
|
911
|
+
},
|
|
912
|
+
error,
|
|
913
|
+
);
|
|
914
|
+
|
|
915
|
+
// ! Progressing from "closed" to "disposing" is not allowed
|
|
916
|
+
if (this._lifecycleState !== "closed") {
|
|
917
|
+
this._lifecycleState = "disposing";
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
this._protocolHandler?.close();
|
|
921
|
+
|
|
922
|
+
this.connectionStateHandler.dispose();
|
|
923
|
+
|
|
924
|
+
this._context?.dispose(error !== undefined ? new Error(error.message) : undefined);
|
|
925
|
+
|
|
926
|
+
this.storageService.dispose();
|
|
927
|
+
|
|
928
|
+
// Notify storage about critical errors. They may be due to disconnect between client & server knowledge
|
|
929
|
+
// about file, like file being overwritten in storage, but client having stale local cache.
|
|
930
|
+
// Driver need to ensure all caches are cleared on critical errors
|
|
931
|
+
this.service?.dispose(error);
|
|
932
|
+
} catch (exception) {
|
|
933
|
+
this.mc.logger.sendErrorEvent(
|
|
934
|
+
{ eventName: "ContainerDisposeException" },
|
|
935
|
+
exception,
|
|
936
|
+
);
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
this.emit("disposed", error);
|
|
940
|
+
|
|
941
|
+
this.removeAllListeners();
|
|
942
|
+
if (this.visibilityEventHandler !== undefined) {
|
|
943
|
+
document.removeEventListener("visibilitychange", this.visibilityEventHandler);
|
|
944
|
+
}
|
|
945
|
+
} finally {
|
|
946
|
+
this._lifecycleState = "disposed";
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
public closeAndGetPendingLocalState(): string {
|
|
951
|
+
// runtime matches pending ops to successful ones by clientId and client seq num, so we need to close the
|
|
952
|
+
// container at the same time we get pending state, otherwise this container could reconnect and resubmit with
|
|
953
|
+
// a new clientId and a future container using stale pending state without the new clientId would resubmit them
|
|
954
|
+
assert(
|
|
955
|
+
this.attachState === AttachState.Attached,
|
|
956
|
+
0x0d1 /* "Container should be attached before close" */,
|
|
957
|
+
);
|
|
958
|
+
assert(
|
|
959
|
+
this.resolvedUrl !== undefined && this.resolvedUrl.type === "fluid",
|
|
960
|
+
0x0d2 /* "resolved url should be valid Fluid url" */,
|
|
961
|
+
);
|
|
962
|
+
assert(!!this._protocolHandler, 0x2e3 /* "Must have a valid protocol handler instance" */);
|
|
963
|
+
assert(
|
|
964
|
+
this._protocolHandler.attributes.term !== undefined,
|
|
965
|
+
0x37e /* Must have a valid protocol handler instance */,
|
|
966
|
+
);
|
|
967
|
+
const pendingState: IPendingContainerState = {
|
|
968
|
+
pendingRuntimeState: this.context.getPendingLocalState(),
|
|
969
|
+
url: this.resolvedUrl.url,
|
|
970
|
+
protocol: this.protocolHandler.getProtocolState(),
|
|
971
|
+
term: this._protocolHandler.attributes.term,
|
|
972
|
+
clientId: this.clientId,
|
|
973
|
+
};
|
|
974
|
+
|
|
975
|
+
this.mc.logger.sendTelemetryEvent({ eventName: "CloseAndGetPendingLocalState" });
|
|
976
|
+
|
|
977
|
+
// Only close here as method name suggests
|
|
978
|
+
this.close();
|
|
979
|
+
|
|
980
|
+
return JSON.stringify(pendingState);
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
public get attachState(): AttachState {
|
|
984
|
+
return this._attachState;
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
public serialize(): string {
|
|
988
|
+
assert(
|
|
989
|
+
this.attachState === AttachState.Detached,
|
|
990
|
+
0x0d3 /* "Should only be called in detached container" */,
|
|
991
|
+
);
|
|
992
|
+
|
|
993
|
+
const appSummary: ISummaryTree = this.context.createSummary();
|
|
994
|
+
const protocolSummary = this.captureProtocolSummary();
|
|
995
|
+
const combinedSummary = combineAppAndProtocolSummary(appSummary, protocolSummary);
|
|
996
|
+
|
|
997
|
+
if (
|
|
998
|
+
this.loader.services.detachedBlobStorage &&
|
|
999
|
+
this.loader.services.detachedBlobStorage.size > 0
|
|
1000
|
+
) {
|
|
1001
|
+
combinedSummary.tree[".hasAttachmentBlobs"] = {
|
|
1002
|
+
type: SummaryType.Blob,
|
|
1003
|
+
content: "true",
|
|
1004
|
+
};
|
|
1005
|
+
}
|
|
1006
|
+
return JSON.stringify(combinedSummary);
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
public async attach(request: IRequest): Promise<void> {
|
|
1010
|
+
await PerformanceEvent.timedExecAsync(
|
|
1011
|
+
this.mc.logger,
|
|
1012
|
+
{ eventName: "Attach" },
|
|
1013
|
+
async () => {
|
|
1014
|
+
if (this._lifecycleState !== "loaded") {
|
|
1015
|
+
// pre-0.58 error message: containerNotValidForAttach
|
|
1016
|
+
throw new UsageError(
|
|
1017
|
+
`The Container is not in a valid state for attach [${this._lifecycleState}]`,
|
|
1018
|
+
);
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
// If container is already attached or attach is in progress, throw an error.
|
|
1022
|
+
assert(
|
|
1023
|
+
this._attachState === AttachState.Detached && !this.attachStarted,
|
|
1024
|
+
0x205 /* "attach() called more than once" */,
|
|
1025
|
+
);
|
|
1026
|
+
this.attachStarted = true;
|
|
1027
|
+
|
|
1028
|
+
// If attachment blobs were uploaded in detached state we will go through a different attach flow
|
|
1029
|
+
const hasAttachmentBlobs =
|
|
1030
|
+
this.loader.services.detachedBlobStorage !== undefined &&
|
|
1031
|
+
this.loader.services.detachedBlobStorage.size > 0;
|
|
1032
|
+
|
|
1033
|
+
try {
|
|
1034
|
+
assert(
|
|
1035
|
+
this.deltaManager.inbound.length === 0,
|
|
1036
|
+
0x0d6 /* "Inbound queue should be empty when attaching" */,
|
|
1037
|
+
);
|
|
1038
|
+
|
|
1039
|
+
let summary: ISummaryTree;
|
|
1040
|
+
if (!hasAttachmentBlobs) {
|
|
1041
|
+
// Get the document state post attach - possibly can just call attach but we need to change the
|
|
1042
|
+
// semantics around what the attach means as far as async code goes.
|
|
1043
|
+
const appSummary: ISummaryTree = this.context.createSummary();
|
|
1044
|
+
const protocolSummary = this.captureProtocolSummary();
|
|
1045
|
+
summary = combineAppAndProtocolSummary(appSummary, protocolSummary);
|
|
1046
|
+
|
|
1047
|
+
// Set the state as attaching as we are starting the process of attaching container.
|
|
1048
|
+
// This should be fired after taking the summary because it is the place where we are
|
|
1049
|
+
// starting to attach the container to storage.
|
|
1050
|
+
// Also, this should only be fired in detached container.
|
|
1051
|
+
this._attachState = AttachState.Attaching;
|
|
1052
|
+
this.context.notifyAttaching(
|
|
1053
|
+
getSnapshotTreeFromSerializedContainer(summary),
|
|
1054
|
+
);
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
// Actually go and create the resolved document
|
|
1058
|
+
const createNewResolvedUrl = await this.urlResolver.resolve(request);
|
|
1059
|
+
ensureFluidResolvedUrl(createNewResolvedUrl);
|
|
1060
|
+
if (this.service === undefined) {
|
|
1061
|
+
assert(
|
|
1062
|
+
this.client.details.type !== summarizerClientType,
|
|
1063
|
+
0x2c4 /* "client should not be summarizer before container is created" */,
|
|
1064
|
+
);
|
|
1065
|
+
this.service = await runWithRetry(
|
|
1066
|
+
async () =>
|
|
1067
|
+
this.serviceFactory.createContainer(
|
|
1068
|
+
summary,
|
|
1069
|
+
createNewResolvedUrl,
|
|
1070
|
+
this.subLogger,
|
|
1071
|
+
false, // clientIsSummarizer
|
|
1072
|
+
),
|
|
1073
|
+
"containerAttach",
|
|
1074
|
+
this.mc.logger,
|
|
1075
|
+
{
|
|
1076
|
+
cancel: this.closeSignal,
|
|
1077
|
+
}, // progress
|
|
1078
|
+
);
|
|
1079
|
+
}
|
|
1080
|
+
const resolvedUrl = this.service.resolvedUrl;
|
|
1081
|
+
ensureFluidResolvedUrl(resolvedUrl);
|
|
1082
|
+
this._resolvedUrl = resolvedUrl;
|
|
1083
|
+
await this.storageService.connectToService(this.service);
|
|
1084
|
+
|
|
1085
|
+
if (hasAttachmentBlobs) {
|
|
1086
|
+
// upload blobs to storage
|
|
1087
|
+
assert(
|
|
1088
|
+
!!this.loader.services.detachedBlobStorage,
|
|
1089
|
+
0x24e /* "assertion for type narrowing" */,
|
|
1090
|
+
);
|
|
1091
|
+
|
|
1092
|
+
// build a table mapping IDs assigned locally to IDs assigned by storage and pass it to runtime to
|
|
1093
|
+
// support blob handles that only know about the local IDs
|
|
1094
|
+
const redirectTable = new Map<string, string>();
|
|
1095
|
+
// if new blobs are added while uploading, upload them too
|
|
1096
|
+
while (redirectTable.size < this.loader.services.detachedBlobStorage.size) {
|
|
1097
|
+
const newIds = this.loader.services.detachedBlobStorage
|
|
1098
|
+
.getBlobIds()
|
|
1099
|
+
.filter((id) => !redirectTable.has(id));
|
|
1100
|
+
for (const id of newIds) {
|
|
1101
|
+
const blob =
|
|
1102
|
+
await this.loader.services.detachedBlobStorage.readBlob(id);
|
|
1103
|
+
const response = await this.storageService.createBlob(blob);
|
|
1104
|
+
redirectTable.set(id, response.id);
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
// take summary and upload
|
|
1109
|
+
const appSummary: ISummaryTree = this.context.createSummary(redirectTable);
|
|
1110
|
+
const protocolSummary = this.captureProtocolSummary();
|
|
1111
|
+
summary = combineAppAndProtocolSummary(appSummary, protocolSummary);
|
|
1112
|
+
|
|
1113
|
+
this._attachState = AttachState.Attaching;
|
|
1114
|
+
this.context.notifyAttaching(
|
|
1115
|
+
getSnapshotTreeFromSerializedContainer(summary),
|
|
1116
|
+
);
|
|
1117
|
+
|
|
1118
|
+
await this.storageService.uploadSummaryWithContext(summary, {
|
|
1119
|
+
referenceSequenceNumber: 0,
|
|
1120
|
+
ackHandle: undefined,
|
|
1121
|
+
proposalHandle: undefined,
|
|
1122
|
+
});
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
this._attachState = AttachState.Attached;
|
|
1126
|
+
this.emit("attached");
|
|
1127
|
+
|
|
1128
|
+
if (!this.closed) {
|
|
1129
|
+
this.resumeInternal({
|
|
1130
|
+
fetchOpsFromStorage: false,
|
|
1131
|
+
reason: "createDetached",
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
} catch (error) {
|
|
1135
|
+
// add resolved URL on error object so that host has the ability to find this document and delete it
|
|
1136
|
+
const newError = normalizeError(error);
|
|
1137
|
+
const resolvedUrl = this.resolvedUrl;
|
|
1138
|
+
if (isFluidResolvedUrl(resolvedUrl)) {
|
|
1139
|
+
newError.addTelemetryProperties({ resolvedUrl: resolvedUrl.url });
|
|
1140
|
+
}
|
|
1141
|
+
this.close(newError);
|
|
1142
|
+
this.dispose?.(newError);
|
|
1143
|
+
throw newError;
|
|
1144
|
+
}
|
|
1145
|
+
},
|
|
1146
|
+
{ start: true, end: true, cancel: "generic" },
|
|
1147
|
+
);
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
public async request(path: IRequest): Promise<IResponse> {
|
|
1151
|
+
return PerformanceEvent.timedExecAsync(
|
|
1152
|
+
this.mc.logger,
|
|
1153
|
+
{ eventName: "Request" },
|
|
1154
|
+
async () => this.context.request(path),
|
|
1155
|
+
{ end: true, cancel: "error" },
|
|
1156
|
+
);
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
private setAutoReconnectInternal(mode: ReconnectMode) {
|
|
1160
|
+
const currentMode = this._deltaManager.connectionManager.reconnectMode;
|
|
1161
|
+
|
|
1162
|
+
if (currentMode === mode) {
|
|
1163
|
+
return;
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
const now = performance.now();
|
|
1167
|
+
const duration = now - this.setAutoReconnectTime;
|
|
1168
|
+
this.setAutoReconnectTime = now;
|
|
1169
|
+
|
|
1170
|
+
this.mc.logger.sendTelemetryEvent({
|
|
1171
|
+
eventName:
|
|
1172
|
+
mode === ReconnectMode.Enabled ? "AutoReconnectEnabled" : "AutoReconnectDisabled",
|
|
1173
|
+
connectionMode: this.connectionMode,
|
|
1174
|
+
connectionState: ConnectionState[this.connectionState],
|
|
1175
|
+
duration,
|
|
1176
|
+
});
|
|
1177
|
+
|
|
1178
|
+
this._deltaManager.connectionManager.setAutoReconnect(mode);
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
public connect() {
|
|
1182
|
+
if (this.closed) {
|
|
1183
|
+
throw new UsageError(`The Container is closed and cannot be connected`);
|
|
1184
|
+
} else if (this._attachState !== AttachState.Attached) {
|
|
1185
|
+
throw new UsageError(`The Container is not attached and cannot be connected`);
|
|
1186
|
+
} else if (!this.connected) {
|
|
1187
|
+
// Note: no need to fetch ops as we do it preemptively as part of DeltaManager.attachOpHandler().
|
|
1188
|
+
// If there is gap, we will learn about it once connected, but the gap should be small (if any),
|
|
1189
|
+
// assuming that connect() is called quickly after initial container boot.
|
|
1190
|
+
this.connectInternal({ reason: "DocumentConnect", fetchOpsFromStorage: false });
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
private connectInternal(args: IConnectionArgs) {
|
|
1195
|
+
assert(!this.closed, 0x2c5 /* "Attempting to connect() a closed Container" */);
|
|
1196
|
+
assert(
|
|
1197
|
+
this._attachState === AttachState.Attached,
|
|
1198
|
+
0x2c6 /* "Attempting to connect() a container that is not attached" */,
|
|
1199
|
+
);
|
|
1200
|
+
|
|
1201
|
+
// Resume processing ops and connect to delta stream
|
|
1202
|
+
this.resumeInternal(args);
|
|
1203
|
+
|
|
1204
|
+
// Set Auto Reconnect Mode
|
|
1205
|
+
const mode = ReconnectMode.Enabled;
|
|
1206
|
+
this.setAutoReconnectInternal(mode);
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
public disconnect() {
|
|
1210
|
+
if (this.closed) {
|
|
1211
|
+
throw new UsageError(`The Container is closed and cannot be disconnected`);
|
|
1212
|
+
} else {
|
|
1213
|
+
this.disconnectInternal();
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
private disconnectInternal() {
|
|
1218
|
+
assert(!this.closed, 0x2c7 /* "Attempting to disconnect() a closed Container" */);
|
|
1219
|
+
|
|
1220
|
+
// Set Auto Reconnect Mode
|
|
1221
|
+
const mode = ReconnectMode.Disabled;
|
|
1222
|
+
this.setAutoReconnectInternal(mode);
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
private resumeInternal(args: IConnectionArgs) {
|
|
1226
|
+
assert(!this.closed, 0x0d9 /* "Attempting to connect() a closed DeltaManager" */);
|
|
1227
|
+
|
|
1228
|
+
// Resume processing ops
|
|
1229
|
+
if (this.inboundQueuePausedFromInit) {
|
|
1230
|
+
this.inboundQueuePausedFromInit = false;
|
|
1231
|
+
this._deltaManager.inbound.resume();
|
|
1232
|
+
this._deltaManager.inboundSignal.resume();
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
// Ensure connection to web socket
|
|
1236
|
+
this.connectToDeltaStream(args);
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
public async getAbsoluteUrl(relativeUrl: string): Promise<string | undefined> {
|
|
1240
|
+
if (this.resolvedUrl === undefined) {
|
|
1241
|
+
return undefined;
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
return this.urlResolver.getAbsoluteUrl(
|
|
1245
|
+
this.resolvedUrl,
|
|
1246
|
+
relativeUrl,
|
|
1247
|
+
getPackageName(this._context?.codeDetails),
|
|
1248
|
+
);
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
public async proposeCodeDetails(codeDetails: IFluidCodeDetails) {
|
|
1252
|
+
if (!isFluidCodeDetails(codeDetails)) {
|
|
1253
|
+
throw new Error("Provided codeDetails are not IFluidCodeDetails");
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
if (this.codeLoader.IFluidCodeDetailsComparer) {
|
|
1257
|
+
const comparison = await this.codeLoader.IFluidCodeDetailsComparer.compare(
|
|
1258
|
+
codeDetails,
|
|
1259
|
+
this.getCodeDetailsFromQuorum(),
|
|
1260
|
+
);
|
|
1261
|
+
if (comparison !== undefined && comparison <= 0) {
|
|
1262
|
+
throw new Error("Proposed code details should be greater than the current");
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
return this.protocolHandler.quorum
|
|
1267
|
+
.propose("code", codeDetails)
|
|
1268
|
+
.then(() => true)
|
|
1269
|
+
.catch(() => false);
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
private async processCodeProposal(): Promise<void> {
|
|
1273
|
+
const codeDetails = this.getCodeDetailsFromQuorum();
|
|
1274
|
+
|
|
1275
|
+
await Promise.all([
|
|
1276
|
+
this.deltaManager.inbound.pause(),
|
|
1277
|
+
this.deltaManager.inboundSignal.pause(),
|
|
1278
|
+
]);
|
|
1279
|
+
|
|
1280
|
+
if ((await this.context.satisfies(codeDetails)) === true) {
|
|
1281
|
+
this.deltaManager.inbound.resume();
|
|
1282
|
+
this.deltaManager.inboundSignal.resume();
|
|
1283
|
+
return;
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
// pre-0.58 error message: existingContextDoesNotSatisfyIncomingProposal
|
|
1287
|
+
const error = new GenericError("Existing context does not satisfy incoming proposal");
|
|
1288
|
+
this.close(error);
|
|
1289
|
+
this.dispose?.(error);
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
private async getVersion(version: string | null): Promise<IVersion | undefined> {
|
|
1293
|
+
const versions = await this.storageService.getVersions(version, 1);
|
|
1294
|
+
return versions[0];
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
private recordConnectStartTime() {
|
|
1298
|
+
if (this.connectionTransitionTimes[ConnectionState.Disconnected] === undefined) {
|
|
1299
|
+
this.connectionTransitionTimes[ConnectionState.Disconnected] = performance.now();
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
private connectToDeltaStream(args: IConnectionArgs) {
|
|
1304
|
+
this.recordConnectStartTime();
|
|
1305
|
+
|
|
1306
|
+
// All agents need "write" access, including summarizer.
|
|
1307
|
+
if (!this._canReconnect || !this.client.details.capabilities.interactive) {
|
|
1308
|
+
args.mode = "write";
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
this._deltaManager.connect(args);
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
/**
|
|
1315
|
+
* Load container.
|
|
1316
|
+
*
|
|
1317
|
+
* @param specifiedVersion - Version SHA to load snapshot. If not specified, will fetch the latest snapshot.
|
|
1318
|
+
*/
|
|
1319
|
+
private async load(
|
|
1320
|
+
specifiedVersion: string | undefined,
|
|
1321
|
+
loadMode: IContainerLoadMode,
|
|
1322
|
+
pendingLocalState?: IPendingContainerState,
|
|
1323
|
+
) {
|
|
1324
|
+
if (this._resolvedUrl === undefined) {
|
|
1325
|
+
throw new Error("Attempting to load without a resolved url");
|
|
1326
|
+
}
|
|
1327
|
+
this.service = await this.serviceFactory.createDocumentService(
|
|
1328
|
+
this._resolvedUrl,
|
|
1329
|
+
this.subLogger,
|
|
1330
|
+
this.client.details.type === summarizerClientType,
|
|
1331
|
+
);
|
|
1332
|
+
|
|
1333
|
+
// Ideally we always connect as "read" by default.
|
|
1334
|
+
// Currently that works with SPO & r11s, because we get "write" connection when connecting to non-existing file.
|
|
1335
|
+
// We should not rely on it by (one of them will address the issue, but we need to address both)
|
|
1336
|
+
// 1) switching create new flow to one where we create file by posting snapshot
|
|
1337
|
+
// 2) Fixing quorum workflows (have retry logic)
|
|
1338
|
+
// That all said, "read" does not work with memorylicious workflows (that opens two simultaneous
|
|
1339
|
+
// connections to same file) in two ways:
|
|
1340
|
+
// A) creation flow breaks (as one of the clients "sees" file as existing, and hits #2 above)
|
|
1341
|
+
// B) Once file is created, transition from view-only connection to write does not work - some bugs to be fixed.
|
|
1342
|
+
const connectionArgs: IConnectionArgs = {
|
|
1343
|
+
reason: "DocumentOpen",
|
|
1344
|
+
mode: "write",
|
|
1345
|
+
fetchOpsFromStorage: false,
|
|
1346
|
+
};
|
|
1347
|
+
|
|
1348
|
+
// Start websocket connection as soon as possible. Note that there is no op handler attached yet, but the
|
|
1349
|
+
// DeltaManager is resilient to this and will wait to start processing ops until after it is attached.
|
|
1350
|
+
if (loadMode.deltaConnection === undefined) {
|
|
1351
|
+
this.connectToDeltaStream(connectionArgs);
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
if (!pendingLocalState) {
|
|
1355
|
+
await this.storageService.connectToService(this.service);
|
|
1356
|
+
} else {
|
|
1357
|
+
// if we have pendingLocalState we can load without storage; don't wait for connection
|
|
1358
|
+
this.storageService.connectToService(this.service).catch((error) => {
|
|
1359
|
+
this.close(error);
|
|
1360
|
+
this.dispose?.(error);
|
|
1361
|
+
});
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
this._attachState = AttachState.Attached;
|
|
1365
|
+
|
|
1366
|
+
// Fetch specified snapshot.
|
|
1367
|
+
const { snapshot, versionId } =
|
|
1368
|
+
pendingLocalState === undefined
|
|
1369
|
+
? await this.fetchSnapshotTree(specifiedVersion)
|
|
1370
|
+
: { snapshot: undefined, versionId: undefined };
|
|
1371
|
+
assert(
|
|
1372
|
+
snapshot !== undefined || pendingLocalState !== undefined,
|
|
1373
|
+
0x237 /* "Snapshot should exist" */,
|
|
1374
|
+
);
|
|
1375
|
+
|
|
1376
|
+
const attributes: IDocumentAttributes =
|
|
1377
|
+
pendingLocalState === undefined
|
|
1378
|
+
? await this.getDocumentAttributes(this.storageService, snapshot)
|
|
1379
|
+
: {
|
|
1380
|
+
sequenceNumber: pendingLocalState.protocol.sequenceNumber,
|
|
1381
|
+
minimumSequenceNumber: pendingLocalState.protocol.minimumSequenceNumber,
|
|
1382
|
+
term: pendingLocalState.term,
|
|
1383
|
+
};
|
|
1384
|
+
|
|
1385
|
+
let opsBeforeReturnP: Promise<void> | undefined;
|
|
1386
|
+
|
|
1387
|
+
// Attach op handlers to finish initialization and be able to start processing ops
|
|
1388
|
+
// Kick off any ops fetching if required.
|
|
1389
|
+
switch (loadMode.opsBeforeReturn) {
|
|
1390
|
+
case undefined:
|
|
1391
|
+
// Start prefetch, but not set opsBeforeReturnP - boot is not blocked by it!
|
|
1392
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
1393
|
+
this.attachDeltaManagerOpHandler(
|
|
1394
|
+
attributes,
|
|
1395
|
+
loadMode.deltaConnection !== "none" ? "all" : "none",
|
|
1396
|
+
);
|
|
1397
|
+
break;
|
|
1398
|
+
case "cached":
|
|
1399
|
+
opsBeforeReturnP = this.attachDeltaManagerOpHandler(attributes, "cached");
|
|
1400
|
+
break;
|
|
1401
|
+
case "all":
|
|
1402
|
+
opsBeforeReturnP = this.attachDeltaManagerOpHandler(attributes, "all");
|
|
1403
|
+
break;
|
|
1404
|
+
default:
|
|
1405
|
+
unreachableCase(loadMode.opsBeforeReturn);
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1408
|
+
// ...load in the existing quorum
|
|
1409
|
+
// Initialize the protocol handler
|
|
1410
|
+
if (pendingLocalState === undefined) {
|
|
1411
|
+
await this.initializeProtocolStateFromSnapshot(
|
|
1412
|
+
attributes,
|
|
1413
|
+
this.storageService,
|
|
1414
|
+
snapshot,
|
|
1415
|
+
);
|
|
1416
|
+
} else {
|
|
1417
|
+
this.initializeProtocolState(
|
|
1418
|
+
attributes,
|
|
1419
|
+
{
|
|
1420
|
+
members: pendingLocalState.protocol.members,
|
|
1421
|
+
proposals: pendingLocalState.protocol.proposals,
|
|
1422
|
+
values: pendingLocalState.protocol.values,
|
|
1423
|
+
}, // pending IQuorumSnapshot
|
|
1424
|
+
);
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
const codeDetails = this.getCodeDetailsFromQuorum();
|
|
1428
|
+
await this.instantiateContext(
|
|
1429
|
+
true, // existing
|
|
1430
|
+
codeDetails,
|
|
1431
|
+
snapshot,
|
|
1432
|
+
pendingLocalState?.pendingRuntimeState,
|
|
1433
|
+
);
|
|
1434
|
+
|
|
1435
|
+
// We might have hit some failure that did not manifest itself in exception in this flow,
|
|
1436
|
+
// do not start op processing in such case - static version of Container.load() will handle it correctly.
|
|
1437
|
+
if (!this.closed) {
|
|
1438
|
+
if (opsBeforeReturnP !== undefined) {
|
|
1439
|
+
this._deltaManager.inbound.resume();
|
|
1440
|
+
|
|
1441
|
+
await PerformanceEvent.timedExecAsync(
|
|
1442
|
+
this.mc.logger,
|
|
1443
|
+
{ eventName: "WaitOps" },
|
|
1444
|
+
async () => opsBeforeReturnP,
|
|
1445
|
+
);
|
|
1446
|
+
await PerformanceEvent.timedExecAsync(
|
|
1447
|
+
this.mc.logger,
|
|
1448
|
+
{ eventName: "WaitOpProcessing" },
|
|
1449
|
+
async () => this._deltaManager.inbound.waitTillProcessingDone(),
|
|
1450
|
+
);
|
|
1451
|
+
|
|
1452
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
1453
|
+
this._deltaManager.inbound.pause();
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
switch (loadMode.deltaConnection) {
|
|
1457
|
+
case undefined:
|
|
1458
|
+
case "delayed":
|
|
1459
|
+
assert(
|
|
1460
|
+
this.inboundQueuePausedFromInit,
|
|
1461
|
+
0x346 /* inboundQueuePausedFromInit should be true */,
|
|
1462
|
+
);
|
|
1463
|
+
this.inboundQueuePausedFromInit = false;
|
|
1464
|
+
this._deltaManager.inbound.resume();
|
|
1465
|
+
this._deltaManager.inboundSignal.resume();
|
|
1466
|
+
break;
|
|
1467
|
+
case "none":
|
|
1468
|
+
break;
|
|
1469
|
+
default:
|
|
1470
|
+
unreachableCase(loadMode.deltaConnection);
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
// Safety net: static version of Container.load() should have learned about it through "closed" handler.
|
|
1475
|
+
// But if that did not happen for some reason, fail load for sure.
|
|
1476
|
+
// Otherwise we can get into situations where container is closed and does not try to connect to ordering
|
|
1477
|
+
// service, but caller does not know that (callers do expect container to be not closed on successful path
|
|
1478
|
+
// and listen only on "closed" event)
|
|
1479
|
+
if (this.closed) {
|
|
1480
|
+
throw new Error("Container was closed while load()");
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
// Internal context is fully loaded at this point
|
|
1484
|
+
this.setLoaded();
|
|
1485
|
+
|
|
1486
|
+
return {
|
|
1487
|
+
sequenceNumber: attributes.sequenceNumber,
|
|
1488
|
+
version: versionId,
|
|
1489
|
+
dmLastProcessedSeqNumber: this._deltaManager.lastSequenceNumber,
|
|
1490
|
+
dmLastKnownSeqNumber: this._deltaManager.lastKnownSeqNumber,
|
|
1491
|
+
};
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
private async createDetached(source: IFluidCodeDetails) {
|
|
1495
|
+
const attributes: IDocumentAttributes = {
|
|
1496
|
+
sequenceNumber: detachedContainerRefSeqNumber,
|
|
1497
|
+
term: 1,
|
|
1498
|
+
minimumSequenceNumber: 0,
|
|
1499
|
+
};
|
|
1500
|
+
|
|
1501
|
+
await this.attachDeltaManagerOpHandler(attributes);
|
|
1502
|
+
|
|
1503
|
+
// Need to just seed the source data in the code quorum. Quorum itself is empty
|
|
1504
|
+
const qValues = initQuorumValuesFromCodeDetails(source);
|
|
1505
|
+
this.initializeProtocolState(
|
|
1506
|
+
attributes,
|
|
1507
|
+
{
|
|
1508
|
+
members: [],
|
|
1509
|
+
proposals: [],
|
|
1510
|
+
values: qValues,
|
|
1511
|
+
}, // IQuorumSnapShot
|
|
1512
|
+
);
|
|
1513
|
+
|
|
1514
|
+
// The load context - given we seeded the quorum - will be great
|
|
1515
|
+
await this.instantiateContextDetached(
|
|
1516
|
+
false, // existing
|
|
1517
|
+
);
|
|
1518
|
+
|
|
1519
|
+
this.setLoaded();
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
private async rehydrateDetachedFromSnapshot(detachedContainerSnapshot: ISummaryTree) {
|
|
1523
|
+
if (detachedContainerSnapshot.tree[".hasAttachmentBlobs"] !== undefined) {
|
|
1524
|
+
assert(
|
|
1525
|
+
!!this.loader.services.detachedBlobStorage &&
|
|
1526
|
+
this.loader.services.detachedBlobStorage.size > 0,
|
|
1527
|
+
0x250 /* "serialized container with attachment blobs must be rehydrated with detached blob storage" */,
|
|
1528
|
+
);
|
|
1529
|
+
delete detachedContainerSnapshot.tree[".hasAttachmentBlobs"];
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
const snapshotTree = getSnapshotTreeFromSerializedContainer(detachedContainerSnapshot);
|
|
1533
|
+
this.storageService.loadSnapshotForRehydratingContainer(snapshotTree);
|
|
1534
|
+
const attributes = await this.getDocumentAttributes(this.storageService, snapshotTree);
|
|
1535
|
+
|
|
1536
|
+
await this.attachDeltaManagerOpHandler(attributes);
|
|
1537
|
+
|
|
1538
|
+
// Initialize the protocol handler
|
|
1539
|
+
const baseTree = getProtocolSnapshotTree(snapshotTree);
|
|
1540
|
+
const qValues = await readAndParse<[string, ICommittedProposal][]>(
|
|
1541
|
+
this.storageService,
|
|
1542
|
+
baseTree.blobs.quorumValues,
|
|
1543
|
+
);
|
|
1544
|
+
const codeDetails = getCodeDetailsFromQuorumValues(qValues);
|
|
1545
|
+
this.initializeProtocolState(
|
|
1546
|
+
attributes,
|
|
1547
|
+
{
|
|
1548
|
+
members: [],
|
|
1549
|
+
proposals: [],
|
|
1550
|
+
values:
|
|
1551
|
+
codeDetails !== undefined ? initQuorumValuesFromCodeDetails(codeDetails) : [],
|
|
1552
|
+
}, // IQuorumSnapShot
|
|
1553
|
+
);
|
|
1554
|
+
|
|
1555
|
+
await this.instantiateContextDetached(
|
|
1556
|
+
true, // existing
|
|
1557
|
+
snapshotTree,
|
|
1558
|
+
);
|
|
1559
|
+
|
|
1560
|
+
this.setLoaded();
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
private async getDocumentAttributes(
|
|
1564
|
+
storage: IDocumentStorageService,
|
|
1565
|
+
tree: ISnapshotTree | undefined,
|
|
1566
|
+
): Promise<IDocumentAttributes> {
|
|
1567
|
+
if (tree === undefined) {
|
|
1568
|
+
return {
|
|
1569
|
+
minimumSequenceNumber: 0,
|
|
1570
|
+
sequenceNumber: 0,
|
|
1571
|
+
term: 1,
|
|
1572
|
+
};
|
|
1573
|
+
}
|
|
1574
|
+
|
|
1575
|
+
// Backward compatibility: old docs would have ".attributes" instead of "attributes"
|
|
1576
|
+
const attributesHash =
|
|
1577
|
+
".protocol" in tree.trees
|
|
1578
|
+
? tree.trees[".protocol"].blobs.attributes
|
|
1579
|
+
: tree.blobs[".attributes"];
|
|
1580
|
+
|
|
1581
|
+
const attributes = await readAndParse<IDocumentAttributes>(storage, attributesHash);
|
|
1582
|
+
|
|
1583
|
+
// Backward compatibility for older summaries with no term
|
|
1584
|
+
if (attributes.term === undefined) {
|
|
1585
|
+
attributes.term = 1;
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
return attributes;
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
private async initializeProtocolStateFromSnapshot(
|
|
1592
|
+
attributes: IDocumentAttributes,
|
|
1593
|
+
storage: IDocumentStorageService,
|
|
1594
|
+
snapshot: ISnapshotTree | undefined,
|
|
1595
|
+
): Promise<void> {
|
|
1596
|
+
const quorumSnapshot: IQuorumSnapshot = {
|
|
1597
|
+
members: [],
|
|
1598
|
+
proposals: [],
|
|
1599
|
+
values: [],
|
|
1600
|
+
};
|
|
1601
|
+
|
|
1602
|
+
if (snapshot !== undefined) {
|
|
1603
|
+
const baseTree = getProtocolSnapshotTree(snapshot);
|
|
1604
|
+
[quorumSnapshot.members, quorumSnapshot.proposals, quorumSnapshot.values] =
|
|
1605
|
+
await Promise.all([
|
|
1606
|
+
readAndParse<[string, ISequencedClient][]>(
|
|
1607
|
+
storage,
|
|
1608
|
+
baseTree.blobs.quorumMembers,
|
|
1609
|
+
),
|
|
1610
|
+
readAndParse<[number, ISequencedProposal, string[]][]>(
|
|
1611
|
+
storage,
|
|
1612
|
+
baseTree.blobs.quorumProposals,
|
|
1613
|
+
),
|
|
1614
|
+
readAndParse<[string, ICommittedProposal][]>(
|
|
1615
|
+
storage,
|
|
1616
|
+
baseTree.blobs.quorumValues,
|
|
1617
|
+
),
|
|
1618
|
+
]);
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
this.initializeProtocolState(attributes, quorumSnapshot);
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1624
|
+
private initializeProtocolState(
|
|
1625
|
+
attributes: IDocumentAttributes,
|
|
1626
|
+
quorumSnapshot: IQuorumSnapshot,
|
|
1627
|
+
): void {
|
|
1628
|
+
const protocolHandlerBuilder =
|
|
1629
|
+
this.protocolHandlerBuilder ??
|
|
1630
|
+
((...args) => new ProtocolHandler(...args, new Audience()));
|
|
1631
|
+
const protocol = protocolHandlerBuilder(attributes, quorumSnapshot, (key, value) =>
|
|
1632
|
+
this.submitMessage(MessageType.Propose, JSON.stringify({ key, value })),
|
|
1633
|
+
);
|
|
1634
|
+
|
|
1635
|
+
const protocolLogger = ChildLogger.create(this.subLogger, "ProtocolHandler");
|
|
1636
|
+
|
|
1637
|
+
protocol.quorum.on("error", (error) => {
|
|
1638
|
+
protocolLogger.sendErrorEvent(error);
|
|
1639
|
+
});
|
|
1640
|
+
|
|
1641
|
+
// Track membership changes and update connection state accordingly
|
|
1642
|
+
this.connectionStateHandler.initProtocol(protocol);
|
|
1643
|
+
|
|
1644
|
+
protocol.quorum.on("addProposal", (proposal: ISequencedProposal) => {
|
|
1645
|
+
if (proposal.key === "code" || proposal.key === "code2") {
|
|
1646
|
+
this.emit("codeDetailsProposed", proposal.value, proposal);
|
|
1647
|
+
}
|
|
1648
|
+
});
|
|
1649
|
+
|
|
1650
|
+
protocol.quorum.on("approveProposal", (sequenceNumber, key, value) => {
|
|
1651
|
+
if (key === "code" || key === "code2") {
|
|
1652
|
+
if (!isFluidCodeDetails(value)) {
|
|
1653
|
+
this.mc.logger.sendErrorEvent({
|
|
1654
|
+
eventName: "CodeProposalNotIFluidCodeDetails",
|
|
1655
|
+
});
|
|
1656
|
+
}
|
|
1657
|
+
this.processCodeProposal().catch((error) => {
|
|
1658
|
+
const normalizedError = normalizeError(error);
|
|
1659
|
+
this.close(normalizedError);
|
|
1660
|
+
this.dispose?.(normalizedError);
|
|
1661
|
+
throw error;
|
|
1662
|
+
});
|
|
1663
|
+
}
|
|
1664
|
+
});
|
|
1665
|
+
// we need to make sure this member get set in a synchronous context,
|
|
1666
|
+
// or other things can happen after the object that will be set is created, but not yet set
|
|
1667
|
+
// this was breaking this._initialClients handling
|
|
1668
|
+
//
|
|
1669
|
+
this._protocolHandler = protocol;
|
|
1670
|
+
}
|
|
1671
|
+
|
|
1672
|
+
private captureProtocolSummary(): ISummaryTree {
|
|
1673
|
+
const quorumSnapshot = this.protocolHandler.snapshot();
|
|
1674
|
+
const summary: ISummaryTree = {
|
|
1675
|
+
tree: {
|
|
1676
|
+
attributes: {
|
|
1677
|
+
content: JSON.stringify(this.protocolHandler.attributes),
|
|
1678
|
+
type: SummaryType.Blob,
|
|
1679
|
+
},
|
|
1680
|
+
quorumMembers: {
|
|
1681
|
+
content: JSON.stringify(quorumSnapshot.members),
|
|
1682
|
+
type: SummaryType.Blob,
|
|
1683
|
+
},
|
|
1684
|
+
quorumProposals: {
|
|
1685
|
+
content: JSON.stringify(quorumSnapshot.proposals),
|
|
1686
|
+
type: SummaryType.Blob,
|
|
1687
|
+
},
|
|
1688
|
+
quorumValues: {
|
|
1689
|
+
content: JSON.stringify(quorumSnapshot.values),
|
|
1690
|
+
type: SummaryType.Blob,
|
|
1691
|
+
},
|
|
1692
|
+
},
|
|
1693
|
+
type: SummaryType.Tree,
|
|
1694
|
+
};
|
|
1695
|
+
|
|
1696
|
+
return summary;
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1699
|
+
private getCodeDetailsFromQuorum(): IFluidCodeDetails {
|
|
1700
|
+
const quorum = this.protocolHandler.quorum;
|
|
1701
|
+
|
|
1702
|
+
const pkg = getCodeProposal(quorum);
|
|
1703
|
+
|
|
1704
|
+
return pkg as IFluidCodeDetails;
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
private get client(): IClient {
|
|
1708
|
+
const client: IClient =
|
|
1709
|
+
this.options?.client !== undefined
|
|
1710
|
+
? (this.options.client as IClient)
|
|
1711
|
+
: {
|
|
1712
|
+
details: {
|
|
1713
|
+
capabilities: { interactive: true },
|
|
1714
|
+
},
|
|
1715
|
+
mode: "read", // default reconnection mode on lost connection / connection error
|
|
1716
|
+
permission: [],
|
|
1717
|
+
scopes: [],
|
|
1718
|
+
user: { id: "" },
|
|
1719
|
+
};
|
|
1720
|
+
|
|
1721
|
+
if (this.clientDetailsOverride !== undefined) {
|
|
1722
|
+
merge(client.details, this.clientDetailsOverride);
|
|
1723
|
+
}
|
|
1724
|
+
client.details.environment = [
|
|
1725
|
+
client.details.environment,
|
|
1726
|
+
` loaderVersion:${pkgVersion}`,
|
|
1727
|
+
].join(";");
|
|
1728
|
+
return client;
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
/**
|
|
1732
|
+
* Returns true if connection is active, i.e. it's "write" connection and
|
|
1733
|
+
* container runtime was notified about this connection (i.e. we are up-to-date and could send ops).
|
|
1734
|
+
* This happens after client received its own joinOp and thus is in the quorum.
|
|
1735
|
+
* If it's not true, runtime is not in position to send ops.
|
|
1736
|
+
*/
|
|
1737
|
+
private activeConnection() {
|
|
1738
|
+
return (
|
|
1739
|
+
this.connectionState === ConnectionState.Connected && this.connectionMode === "write"
|
|
1740
|
+
);
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
private createDeltaManager() {
|
|
1744
|
+
const serviceProvider = () => this.service;
|
|
1745
|
+
const deltaManager = new DeltaManager<ConnectionManager>(
|
|
1746
|
+
serviceProvider,
|
|
1747
|
+
ChildLogger.create(this.subLogger, "DeltaManager"),
|
|
1748
|
+
() => this.activeConnection(),
|
|
1749
|
+
(props: IConnectionManagerFactoryArgs) =>
|
|
1750
|
+
new ConnectionManager(
|
|
1751
|
+
serviceProvider,
|
|
1752
|
+
this.client,
|
|
1753
|
+
this._canReconnect,
|
|
1754
|
+
ChildLogger.create(this.subLogger, "ConnectionManager"),
|
|
1755
|
+
props,
|
|
1756
|
+
),
|
|
1757
|
+
);
|
|
1758
|
+
|
|
1759
|
+
// Disable inbound queues as Container is not ready to accept any ops until we are fully loaded!
|
|
1760
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
1761
|
+
deltaManager.inbound.pause();
|
|
1762
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
1763
|
+
deltaManager.inboundSignal.pause();
|
|
1764
|
+
|
|
1765
|
+
deltaManager.on("connect", (details: IConnectionDetails, _opsBehind?: number) => {
|
|
1766
|
+
assert(this.connectionMode === details.mode, 0x4b7 /* mismatch */);
|
|
1767
|
+
this.connectionStateHandler.receivedConnectEvent(details);
|
|
1768
|
+
});
|
|
1769
|
+
|
|
1770
|
+
deltaManager.on("disconnect", (reason: string) => {
|
|
1771
|
+
this.collabWindowTracker?.stopSequenceNumberUpdate();
|
|
1772
|
+
if (!this.closed) {
|
|
1773
|
+
this.connectionStateHandler.receivedDisconnectEvent(reason);
|
|
1774
|
+
}
|
|
1775
|
+
});
|
|
1776
|
+
|
|
1777
|
+
deltaManager.on("throttled", (warning: IThrottlingWarning) => {
|
|
1778
|
+
const warn = warning as ContainerWarning;
|
|
1779
|
+
// Some "warning" events come from outside the container and are logged
|
|
1780
|
+
// elsewhere (e.g. summarizing container). We shouldn't log these here.
|
|
1781
|
+
if (warn.logged !== true) {
|
|
1782
|
+
this.mc.logger.sendTelemetryEvent({ eventName: "ContainerWarning" }, warn);
|
|
1783
|
+
}
|
|
1784
|
+
this.emit("warning", warn);
|
|
1785
|
+
});
|
|
1786
|
+
|
|
1787
|
+
deltaManager.on("readonly", (readonly) => {
|
|
1788
|
+
this.setContextConnectedState(
|
|
1789
|
+
this.connectionState === ConnectionState.Connected,
|
|
1790
|
+
readonly,
|
|
1791
|
+
);
|
|
1792
|
+
this.emit("readonly", readonly);
|
|
1793
|
+
});
|
|
1794
|
+
|
|
1795
|
+
deltaManager.on("closed", (error?: ICriticalContainerError) => {
|
|
1796
|
+
this.closeCore(error);
|
|
1797
|
+
});
|
|
1798
|
+
|
|
1799
|
+
deltaManager.on("disposed", (error?: ICriticalContainerError) => {
|
|
1800
|
+
this.disposeCore(error);
|
|
1801
|
+
});
|
|
1802
|
+
|
|
1803
|
+
return deltaManager;
|
|
1804
|
+
}
|
|
1805
|
+
|
|
1806
|
+
private async attachDeltaManagerOpHandler(
|
|
1807
|
+
attributes: IDocumentAttributes,
|
|
1808
|
+
prefetchType?: "cached" | "all" | "none",
|
|
1809
|
+
) {
|
|
1810
|
+
return this._deltaManager.attachOpHandler(
|
|
1811
|
+
attributes.minimumSequenceNumber,
|
|
1812
|
+
attributes.sequenceNumber,
|
|
1813
|
+
attributes.term ?? 1,
|
|
1814
|
+
{
|
|
1815
|
+
process: (message) => this.processRemoteMessage(message),
|
|
1816
|
+
processSignal: (message) => {
|
|
1817
|
+
this.processSignal(message);
|
|
1818
|
+
},
|
|
1819
|
+
},
|
|
1820
|
+
prefetchType,
|
|
1821
|
+
);
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
private logConnectionStateChangeTelemetry(
|
|
1825
|
+
value: ConnectionState,
|
|
1826
|
+
oldState: ConnectionState,
|
|
1827
|
+
reason?: string,
|
|
1828
|
+
) {
|
|
1829
|
+
// Log actual event
|
|
1830
|
+
const time = performance.now();
|
|
1831
|
+
this.connectionTransitionTimes[value] = time;
|
|
1832
|
+
const duration = time - this.connectionTransitionTimes[oldState];
|
|
1833
|
+
|
|
1834
|
+
let durationFromDisconnected: number | undefined;
|
|
1835
|
+
let connectionInitiationReason: string | undefined;
|
|
1836
|
+
let autoReconnect: ReconnectMode | undefined;
|
|
1837
|
+
let checkpointSequenceNumber: number | undefined;
|
|
1838
|
+
let opsBehind: number | undefined;
|
|
1839
|
+
if (value === ConnectionState.Disconnected) {
|
|
1840
|
+
autoReconnect = this._deltaManager.connectionManager.reconnectMode;
|
|
1841
|
+
} else {
|
|
1842
|
+
if (value === ConnectionState.Connected) {
|
|
1843
|
+
durationFromDisconnected =
|
|
1844
|
+
time - this.connectionTransitionTimes[ConnectionState.Disconnected];
|
|
1845
|
+
durationFromDisconnected = TelemetryLogger.formatTick(durationFromDisconnected);
|
|
1846
|
+
} else {
|
|
1847
|
+
// This info is of most interest on establishing connection only.
|
|
1848
|
+
checkpointSequenceNumber = this.deltaManager.lastKnownSeqNumber;
|
|
1849
|
+
if (this.deltaManager.hasCheckpointSequenceNumber) {
|
|
1850
|
+
opsBehind = checkpointSequenceNumber - this.deltaManager.lastSequenceNumber;
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
connectionInitiationReason = this.firstConnection ? "InitialConnect" : "AutoReconnect";
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1856
|
+
this.mc.logger.sendPerformanceEvent({
|
|
1857
|
+
eventName: `ConnectionStateChange_${ConnectionState[value]}`,
|
|
1858
|
+
from: ConnectionState[oldState],
|
|
1859
|
+
duration,
|
|
1860
|
+
durationFromDisconnected,
|
|
1861
|
+
reason,
|
|
1862
|
+
connectionInitiationReason,
|
|
1863
|
+
pendingClientId: this.connectionStateHandler.pendingClientId,
|
|
1864
|
+
clientId: this.clientId,
|
|
1865
|
+
autoReconnect,
|
|
1866
|
+
opsBehind,
|
|
1867
|
+
online: OnlineStatus[isOnline()],
|
|
1868
|
+
lastVisible:
|
|
1869
|
+
this.lastVisible !== undefined ? performance.now() - this.lastVisible : undefined,
|
|
1870
|
+
checkpointSequenceNumber,
|
|
1871
|
+
quorumSize: this._protocolHandler?.quorum.getMembers().size,
|
|
1872
|
+
...this._deltaManager.connectionProps,
|
|
1873
|
+
});
|
|
1874
|
+
|
|
1875
|
+
if (value === ConnectionState.Connected) {
|
|
1876
|
+
this.firstConnection = false;
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
|
|
1880
|
+
private propagateConnectionState(initialTransition: boolean, disconnectedReason?: string) {
|
|
1881
|
+
// When container loaded, we want to propagate initial connection state.
|
|
1882
|
+
// After that, we communicate only transitions to Connected & Disconnected states, skipping all other states.
|
|
1883
|
+
// This can be changed in the future, for example we likely should add "CatchingUp" event on Container.
|
|
1884
|
+
if (
|
|
1885
|
+
!initialTransition &&
|
|
1886
|
+
this.connectionState !== ConnectionState.Connected &&
|
|
1887
|
+
this.connectionState !== ConnectionState.Disconnected
|
|
1888
|
+
) {
|
|
1889
|
+
return;
|
|
1890
|
+
}
|
|
1891
|
+
const state = this.connectionState === ConnectionState.Connected;
|
|
1892
|
+
|
|
1893
|
+
const logOpsOnReconnect: boolean =
|
|
1894
|
+
this.connectionState === ConnectionState.Connected &&
|
|
1895
|
+
!this.firstConnection &&
|
|
1896
|
+
this.connectionMode === "write";
|
|
1897
|
+
if (logOpsOnReconnect) {
|
|
1898
|
+
this.messageCountAfterDisconnection = 0;
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
// Both protocol and context should not be undefined if we got so far.
|
|
1902
|
+
|
|
1903
|
+
this.setContextConnectedState(
|
|
1904
|
+
state,
|
|
1905
|
+
this._deltaManager.connectionManager.readOnlyInfo.readonly ?? false,
|
|
1906
|
+
);
|
|
1907
|
+
this.protocolHandler.setConnectionState(state, this.clientId);
|
|
1908
|
+
raiseConnectedEvent(this.mc.logger, this, state, this.clientId, disconnectedReason);
|
|
1909
|
+
|
|
1910
|
+
if (logOpsOnReconnect) {
|
|
1911
|
+
this.mc.logger.sendTelemetryEvent({
|
|
1912
|
+
eventName: "OpsSentOnReconnect",
|
|
1913
|
+
count: this.messageCountAfterDisconnection,
|
|
1914
|
+
});
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
|
|
1918
|
+
// back-compat: ADO #1385: Remove in the future, summary op should come through submitSummaryMessage()
|
|
1919
|
+
private submitContainerMessage(
|
|
1920
|
+
type: MessageType,
|
|
1921
|
+
contents: any,
|
|
1922
|
+
batch?: boolean,
|
|
1923
|
+
metadata?: any,
|
|
1924
|
+
): number {
|
|
1925
|
+
switch (type) {
|
|
1926
|
+
case MessageType.Operation:
|
|
1927
|
+
return this.submitMessage(type, JSON.stringify(contents), batch, metadata);
|
|
1928
|
+
case MessageType.Summarize:
|
|
1929
|
+
return this.submitSummaryMessage(contents as unknown as ISummaryContent);
|
|
1930
|
+
default: {
|
|
1931
|
+
const newError = new GenericError(
|
|
1932
|
+
"invalidContainerSubmitOpType",
|
|
1933
|
+
undefined /* error */,
|
|
1934
|
+
{ messageType: type },
|
|
1935
|
+
);
|
|
1936
|
+
this.close(newError);
|
|
1937
|
+
this.dispose?.(newError);
|
|
1938
|
+
return -1;
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1943
|
+
/** @returns clientSequenceNumber of last message in a batch */
|
|
1944
|
+
private submitBatch(batch: IBatchMessage[]): number {
|
|
1945
|
+
let clientSequenceNumber = -1;
|
|
1946
|
+
for (const message of batch) {
|
|
1947
|
+
clientSequenceNumber = this.submitMessage(
|
|
1948
|
+
MessageType.Operation,
|
|
1949
|
+
message.contents,
|
|
1950
|
+
true, // batch
|
|
1951
|
+
message.metadata,
|
|
1952
|
+
message.compression,
|
|
1953
|
+
);
|
|
1954
|
+
}
|
|
1955
|
+
this._deltaManager.flush();
|
|
1956
|
+
return clientSequenceNumber;
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1959
|
+
private submitSummaryMessage(summary: ISummaryContent) {
|
|
1960
|
+
// github #6451: this is only needed for staging so the server
|
|
1961
|
+
// know when the protocol tree is included
|
|
1962
|
+
// this can be removed once all clients send
|
|
1963
|
+
// protocol tree by default
|
|
1964
|
+
if (summary.details === undefined) {
|
|
1965
|
+
summary.details = {};
|
|
1966
|
+
}
|
|
1967
|
+
summary.details.includesProtocolTree = this.options.summarizeProtocolTree === true;
|
|
1968
|
+
return this.submitMessage(
|
|
1969
|
+
MessageType.Summarize,
|
|
1970
|
+
JSON.stringify(summary),
|
|
1971
|
+
false /* batch */,
|
|
1972
|
+
);
|
|
1973
|
+
}
|
|
1974
|
+
|
|
1975
|
+
private submitMessage(
|
|
1976
|
+
type: MessageType,
|
|
1977
|
+
contents?: string,
|
|
1978
|
+
batch?: boolean,
|
|
1979
|
+
metadata?: any,
|
|
1980
|
+
compression?: string,
|
|
1981
|
+
): number {
|
|
1982
|
+
if (this.connectionState !== ConnectionState.Connected) {
|
|
1983
|
+
this.mc.logger.sendErrorEvent({ eventName: "SubmitMessageWithNoConnection", type });
|
|
1984
|
+
return -1;
|
|
1985
|
+
}
|
|
1986
|
+
|
|
1987
|
+
this.messageCountAfterDisconnection += 1;
|
|
1988
|
+
this.collabWindowTracker?.stopSequenceNumberUpdate();
|
|
1989
|
+
return this._deltaManager.submit(type, contents, batch, metadata, compression);
|
|
1990
|
+
}
|
|
1991
|
+
|
|
1992
|
+
private processRemoteMessage(message: ISequencedDocumentMessage) {
|
|
1993
|
+
const local = this.clientId === message.clientId;
|
|
1994
|
+
|
|
1995
|
+
// Allow the protocol handler to process the message
|
|
1996
|
+
const result = this.protocolHandler.processMessage(message, local);
|
|
1997
|
+
|
|
1998
|
+
// Forward messages to the loaded runtime for processing
|
|
1999
|
+
this.context.process(message, local);
|
|
2000
|
+
|
|
2001
|
+
// Inactive (not in quorum or not writers) clients don't take part in the minimum sequence number calculation.
|
|
2002
|
+
if (this.activeConnection()) {
|
|
2003
|
+
if (this.collabWindowTracker === undefined) {
|
|
2004
|
+
// Note that config from first connection will be used for this container's lifetime.
|
|
2005
|
+
// That means that if relay service changes settings, such changes will impact only newly booted
|
|
2006
|
+
// clients.
|
|
2007
|
+
// All existing will continue to use settings they got earlier.
|
|
2008
|
+
assert(
|
|
2009
|
+
this.serviceConfiguration !== undefined,
|
|
2010
|
+
0x2e4 /* "there should be service config for active connection" */,
|
|
2011
|
+
);
|
|
2012
|
+
this.collabWindowTracker = new CollabWindowTracker(
|
|
2013
|
+
(type) => {
|
|
2014
|
+
assert(
|
|
2015
|
+
this.activeConnection(),
|
|
2016
|
+
0x241 /* "disconnect should result in stopSequenceNumberUpdate() call" */,
|
|
2017
|
+
);
|
|
2018
|
+
this.submitMessage(type);
|
|
2019
|
+
},
|
|
2020
|
+
this.serviceConfiguration.noopTimeFrequency,
|
|
2021
|
+
this.serviceConfiguration.noopCountFrequency,
|
|
2022
|
+
);
|
|
2023
|
+
}
|
|
2024
|
+
this.collabWindowTracker.scheduleSequenceNumberUpdate(
|
|
2025
|
+
message,
|
|
2026
|
+
result.immediateNoOp === true,
|
|
2027
|
+
);
|
|
2028
|
+
}
|
|
2029
|
+
|
|
2030
|
+
this.emit("op", message);
|
|
2031
|
+
}
|
|
2032
|
+
|
|
2033
|
+
private submitSignal(message: any) {
|
|
2034
|
+
this._deltaManager.submitSignal(JSON.stringify(message));
|
|
2035
|
+
}
|
|
2036
|
+
|
|
2037
|
+
private processSignal(message: ISignalMessage) {
|
|
2038
|
+
// No clientId indicates a system signal message.
|
|
2039
|
+
if (message.clientId === null) {
|
|
2040
|
+
this.protocolHandler.processSignal(message);
|
|
2041
|
+
} else {
|
|
2042
|
+
const local = this.clientId === message.clientId;
|
|
2043
|
+
this.context.processSignal(message, local);
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
|
|
2047
|
+
/**
|
|
2048
|
+
* Get the most recent snapshot, or a specific version.
|
|
2049
|
+
* @param specifiedVersion - The specific version of the snapshot to retrieve
|
|
2050
|
+
* @returns The snapshot requested, or the latest snapshot if no version was specified, plus version ID
|
|
2051
|
+
*/
|
|
2052
|
+
private async fetchSnapshotTree(
|
|
2053
|
+
specifiedVersion: string | undefined,
|
|
2054
|
+
): Promise<{ snapshot?: ISnapshotTree; versionId?: string }> {
|
|
2055
|
+
const version = await this.getVersion(specifiedVersion ?? null);
|
|
2056
|
+
|
|
2057
|
+
if (version === undefined && specifiedVersion !== undefined) {
|
|
2058
|
+
// We should have a defined version to load from if specified version requested
|
|
2059
|
+
this.mc.logger.sendErrorEvent({
|
|
2060
|
+
eventName: "NoVersionFoundWhenSpecified",
|
|
2061
|
+
id: specifiedVersion,
|
|
2062
|
+
});
|
|
2063
|
+
}
|
|
2064
|
+
this._loadedFromVersion = version;
|
|
2065
|
+
const snapshot = (await this.storageService.getSnapshotTree(version)) ?? undefined;
|
|
2066
|
+
|
|
2067
|
+
if (snapshot === undefined && version !== undefined) {
|
|
2068
|
+
this.mc.logger.sendErrorEvent({ eventName: "getSnapshotTreeFailed", id: version.id });
|
|
2069
|
+
}
|
|
2070
|
+
return { snapshot, versionId: version?.id };
|
|
2071
|
+
}
|
|
2072
|
+
|
|
2073
|
+
private async instantiateContextDetached(existing: boolean, snapshot?: ISnapshotTree) {
|
|
2074
|
+
const codeDetails = this.getCodeDetailsFromQuorum();
|
|
2075
|
+
if (codeDetails === undefined) {
|
|
2076
|
+
throw new Error("pkg should be provided in create flow!!");
|
|
2077
|
+
}
|
|
2078
|
+
|
|
2079
|
+
await this.instantiateContext(existing, codeDetails, snapshot);
|
|
2080
|
+
}
|
|
2081
|
+
|
|
2082
|
+
private async instantiateContext(
|
|
2083
|
+
existing: boolean,
|
|
2084
|
+
codeDetails: IFluidCodeDetails,
|
|
2085
|
+
snapshot?: ISnapshotTree,
|
|
2086
|
+
pendingLocalState?: unknown,
|
|
2087
|
+
) {
|
|
2088
|
+
assert(this._context?.disposed !== false, 0x0dd /* "Existing context not disposed" */);
|
|
2089
|
+
|
|
2090
|
+
// The relative loader will proxy requests to '/' to the loader itself assuming no non-cache flags
|
|
2091
|
+
// are set. Global requests will still go directly to the loader
|
|
2092
|
+
const loader = new RelativeLoader(this, this.loader);
|
|
2093
|
+
this._context = await ContainerContext.createOrLoad(
|
|
2094
|
+
this,
|
|
2095
|
+
this.scope,
|
|
2096
|
+
this.codeLoader,
|
|
2097
|
+
codeDetails,
|
|
2098
|
+
snapshot,
|
|
2099
|
+
new DeltaManagerProxy(this._deltaManager),
|
|
2100
|
+
new QuorumProxy(this.protocolHandler.quorum),
|
|
2101
|
+
loader,
|
|
2102
|
+
(type, contents, batch, metadata) =>
|
|
2103
|
+
this.submitContainerMessage(type, contents, batch, metadata),
|
|
2104
|
+
(summaryOp: ISummaryContent) => this.submitSummaryMessage(summaryOp),
|
|
2105
|
+
(batch: IBatchMessage[]) => this.submitBatch(batch),
|
|
2106
|
+
(message) => this.submitSignal(message),
|
|
2107
|
+
(error?: ICriticalContainerError) => this.dispose?.(error),
|
|
2108
|
+
(error?: ICriticalContainerError) => this.close(error),
|
|
2109
|
+
Container.version,
|
|
2110
|
+
(dirty: boolean) => this.updateDirtyContainerState(dirty),
|
|
2111
|
+
existing,
|
|
2112
|
+
pendingLocalState,
|
|
2113
|
+
);
|
|
2114
|
+
|
|
2115
|
+
this.emit("contextChanged", codeDetails);
|
|
2116
|
+
}
|
|
2117
|
+
|
|
2118
|
+
private updateDirtyContainerState(dirty: boolean) {
|
|
2119
|
+
if (this._dirtyContainer === dirty) {
|
|
2120
|
+
return;
|
|
2121
|
+
}
|
|
2122
|
+
this._dirtyContainer = dirty;
|
|
2123
|
+
this.emit(dirty ? dirtyContainerEvent : savedContainerEvent);
|
|
2124
|
+
}
|
|
2125
|
+
|
|
2126
|
+
/**
|
|
2127
|
+
* Set the connected state of the ContainerContext
|
|
2128
|
+
* This controls the "connected" state of the ContainerRuntime as well
|
|
2129
|
+
* @param state - Is the container currently connected?
|
|
2130
|
+
* @param readonly - Is the container in readonly mode?
|
|
2131
|
+
*/
|
|
2132
|
+
private setContextConnectedState(state: boolean, readonly: boolean): void {
|
|
2133
|
+
if (this._context?.disposed === false) {
|
|
2134
|
+
/**
|
|
2135
|
+
* We want to lie to the ContainerRuntime when we are in readonly mode to prevent issues with pending
|
|
2136
|
+
* ops getting through to the DeltaManager.
|
|
2137
|
+
* The ContainerRuntime's "connected" state simply means it is ok to send ops
|
|
2138
|
+
* See https://dev.azure.com/fluidframework/internal/_workitems/edit/1246
|
|
2139
|
+
*/
|
|
2140
|
+
this.context.setConnectionState(state && !readonly, this.clientId);
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
1996
2143
|
}
|