@fluidframework/driver-base 2.0.0-internal.1.4.4 → 2.0.0-internal.2.0.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/dist/documentDeltaConnection.d.ts +10 -7
- package/dist/documentDeltaConnection.d.ts.map +1 -1
- package/dist/documentDeltaConnection.js +33 -18
- package/dist/documentDeltaConnection.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/lib/documentDeltaConnection.d.ts +10 -7
- package/lib/documentDeltaConnection.d.ts.map +1 -1
- package/lib/documentDeltaConnection.js +33 -18
- package/lib/documentDeltaConnection.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/package.json +10 -9
- package/src/documentDeltaConnection.ts +41 -22
- package/src/packageVersion.ts +1 -1
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { IDocumentDeltaConnection, IDocumentDeltaConnectionEvents } from "@fluidframework/driver-definitions";
|
|
6
|
-
import { IAnyDriverError } from "@fluidframework/driver-utils";
|
|
5
|
+
import { IAnyDriverError, IDocumentDeltaConnection, IDocumentDeltaConnectionEvents } from "@fluidframework/driver-definitions";
|
|
7
6
|
import { ConnectionMode, IClientConfiguration, IConnect, IConnected, IDocumentMessage, ISequencedDocumentMessage, ISignalClient, ISignalMessage, ITokenClaims } from "@fluidframework/protocol-definitions";
|
|
8
7
|
import { IDisposable, ITelemetryLogger } from "@fluidframework/common-definitions";
|
|
9
8
|
import { EventEmitterWithErrorHandling } from "@fluidframework/telemetry-utils";
|
|
@@ -128,17 +127,21 @@ export declare class DocumentDeltaConnection extends EventEmitterWithErrorHandli
|
|
|
128
127
|
*/
|
|
129
128
|
submitSignal(message: IDocumentMessage): void;
|
|
130
129
|
/**
|
|
131
|
-
* Disconnect from the websocket
|
|
130
|
+
* Disconnect from the websocket and close the websocket too.
|
|
131
|
+
*/
|
|
132
|
+
protected closeSocket(error: IAnyDriverError): void;
|
|
133
|
+
/**
|
|
134
|
+
* Disconnect from the websocket, and permanently disable this DocumentDeltaConnection and close the socket.
|
|
135
|
+
* However the OdspDocumentDeltaConnection differ in dispose as in there we don't close the socket. There is no
|
|
136
|
+
* multiplexing here, so we need to close the socket here.
|
|
132
137
|
*/
|
|
133
138
|
dispose(): void;
|
|
134
|
-
protected
|
|
139
|
+
protected disconnect(err: IAnyDriverError): void;
|
|
135
140
|
/**
|
|
136
141
|
* Disconnect from the websocket.
|
|
137
|
-
* @param socketProtocolError - true if error happened on socket / socket.io protocol level
|
|
138
|
-
* (not on Fluid protocol level)
|
|
139
142
|
* @param reason - reason for disconnect
|
|
140
143
|
*/
|
|
141
|
-
protected
|
|
144
|
+
protected disconnectCore(): void;
|
|
142
145
|
protected initialize(connectMessage: IConnect, timeout: number): Promise<void>;
|
|
143
146
|
protected earlyOpHandler: (documentId: string, msgs: ISequencedDocumentMessage[]) => void;
|
|
144
147
|
protected earlySignalHandler: (msg: ISignalMessage) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentDeltaConnection.d.ts","sourceRoot":"","sources":["../src/documentDeltaConnection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACH,wBAAwB,EACxB,8BAA8B,EACjC,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"documentDeltaConnection.d.ts","sourceRoot":"","sources":["../src/documentDeltaConnection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACH,eAAe,EACf,wBAAwB,EACxB,8BAA8B,EACjC,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EACH,cAAc,EACd,oBAAoB,EACpB,QAAQ,EACR,UAAU,EACV,gBAAgB,EAChB,y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,eAAgB,MAAM,QAAQ,yBAAyB,EAAE,UAE/E;IAEF,SAAS,CAAC,kBAAkB,QAAS,cAAc,UAEjD;IAEF,OAAO,CAAC,oBAAoB;IAK5B,OAAO,CAAC,wBAAwB;IAIhC,OAAO,CAAC,qBAAqB;IAU7B,SAAS,CAAC,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI;IAM9E,OAAO,CAAC,sBAAsB;IAa9B,OAAO,CAAC,yBAAyB;IAWjC;;OAEG;IACH,SAAS,CAAC,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG,EAAE,QAAQ,UAAO,GAAG,eAAe;CA2B9F"}
|
|
@@ -230,15 +230,22 @@ class DocumentDeltaConnection extends telemetry_utils_1.EventEmitterWithErrorHan
|
|
|
230
230
|
this.submitCore("submitSignal", [message]);
|
|
231
231
|
}
|
|
232
232
|
/**
|
|
233
|
-
* Disconnect from the websocket
|
|
233
|
+
* Disconnect from the websocket and close the websocket too.
|
|
234
|
+
*/
|
|
235
|
+
closeSocket(error) {
|
|
236
|
+
this.disconnect(error);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Disconnect from the websocket, and permanently disable this DocumentDeltaConnection and close the socket.
|
|
240
|
+
* However the OdspDocumentDeltaConnection differ in dispose as in there we don't close the socket. There is no
|
|
241
|
+
* multiplexing here, so we need to close the socket here.
|
|
234
242
|
*/
|
|
235
243
|
dispose() {
|
|
236
|
-
this.
|
|
237
|
-
(0, driver_utils_1.createGenericNetworkError)(
|
|
244
|
+
this.disconnect((0, driver_utils_1.createGenericNetworkError)(
|
|
238
245
|
// pre-0.58 error message: clientClosingConnection
|
|
239
246
|
"Client closing delta connection", { canRetry: true }, { driverVersion: packageVersion_1.pkgVersion }));
|
|
240
247
|
}
|
|
241
|
-
|
|
248
|
+
disconnect(err) {
|
|
242
249
|
// Can't check this.disposed here, as we get here on socket closure,
|
|
243
250
|
// so _disposed & socket.connected might be not in sync while processing
|
|
244
251
|
// "dispose" event.
|
|
@@ -251,16 +258,20 @@ class DocumentDeltaConnection extends telemetry_utils_1.EventEmitterWithErrorHan
|
|
|
251
258
|
// OdspDocumentDeltaConnection may still send disconnect_document which is allowed; this is only intended
|
|
252
259
|
// to prevent normal messages from being emitted.
|
|
253
260
|
this._disposed = true;
|
|
261
|
+
// Let user of connection object know about disconnect. This has to happen in betwee setting _disposed and
|
|
262
|
+
// removing all listeners!
|
|
263
|
+
this.emit("disconnect", err);
|
|
264
|
+
// user of DeltaConnection should have processed "disconnect" event and removed all listeners. Not clear
|
|
265
|
+
// if we want to enforce that, as some users (like LocalDocumentService) do not unregister any handlers
|
|
266
|
+
// assert(this.listenerCount("disconnect") === 0, "'disconnect` events should be processed synchronously");
|
|
254
267
|
this.removeTrackedListeners();
|
|
255
|
-
this.
|
|
268
|
+
this.disconnectCore();
|
|
256
269
|
}
|
|
257
270
|
/**
|
|
258
271
|
* Disconnect from the websocket.
|
|
259
|
-
* @param socketProtocolError - true if error happened on socket / socket.io protocol level
|
|
260
|
-
* (not on Fluid protocol level)
|
|
261
272
|
* @param reason - reason for disconnect
|
|
262
273
|
*/
|
|
263
|
-
|
|
274
|
+
disconnectCore() {
|
|
264
275
|
this.socket.disconnect();
|
|
265
276
|
}
|
|
266
277
|
async initialize(connectMessage, timeout) {
|
|
@@ -275,8 +286,12 @@ class DocumentDeltaConnection extends telemetry_utils_1.EventEmitterWithErrorHan
|
|
|
275
286
|
: 0;
|
|
276
287
|
const getMaxAllowedInternalSocketConnectionFailures = () => getMaxInternalSocketReconnectionAttempts() + 1;
|
|
277
288
|
this._details = await new Promise((resolve, reject) => {
|
|
278
|
-
const
|
|
279
|
-
this.
|
|
289
|
+
const failAndCloseSocket = (err) => {
|
|
290
|
+
this.closeSocket(err);
|
|
291
|
+
reject(err);
|
|
292
|
+
};
|
|
293
|
+
const failConnection = (err) => {
|
|
294
|
+
this.disconnect(err);
|
|
280
295
|
reject(err);
|
|
281
296
|
};
|
|
282
297
|
// Listen for connection issues
|
|
@@ -314,11 +329,11 @@ class DocumentDeltaConnection extends telemetry_utils_1.EventEmitterWithErrorHan
|
|
|
314
329
|
// Reconnection is enabled and maximum reconnect attempts have not been reached.
|
|
315
330
|
return;
|
|
316
331
|
}
|
|
317
|
-
|
|
332
|
+
failAndCloseSocket(this.createErrorObject("connect_error", error));
|
|
318
333
|
});
|
|
319
334
|
// Listen for timeouts
|
|
320
335
|
this.addConnectionListener("connect_timeout", () => {
|
|
321
|
-
|
|
336
|
+
failAndCloseSocket(this.createErrorObject("connect_timeout"));
|
|
322
337
|
});
|
|
323
338
|
this.addConnectionListener("connect_document_success", (response) => {
|
|
324
339
|
// If we sent a nonce and the server supports nonces, check that the nonces match
|
|
@@ -334,13 +349,13 @@ class DocumentDeltaConnection extends telemetry_utils_1.EventEmitterWithErrorHan
|
|
|
334
349
|
// The only time we expect a mismatch in requested/actual is if we lack write permissions
|
|
335
350
|
// In this case we will get "read", even if we requested "write"
|
|
336
351
|
if (actualMode !== requestedMode) {
|
|
337
|
-
|
|
352
|
+
failConnection(this.createErrorObject("connect_document_success", "Connected in a different mode than was requested", false));
|
|
338
353
|
return;
|
|
339
354
|
}
|
|
340
355
|
}
|
|
341
356
|
else {
|
|
342
357
|
if (actualMode === "write") {
|
|
343
|
-
|
|
358
|
+
failConnection(this.createErrorObject("connect_document_success", "Connected in write mode without write permissions", false));
|
|
344
359
|
return;
|
|
345
360
|
}
|
|
346
361
|
}
|
|
@@ -354,7 +369,7 @@ class DocumentDeltaConnection extends telemetry_utils_1.EventEmitterWithErrorHan
|
|
|
354
369
|
this.addTrackedListener("disconnect", (reason) => {
|
|
355
370
|
const err = this.createErrorObject("disconnect", reason);
|
|
356
371
|
this.emit("disconnect", err);
|
|
357
|
-
|
|
372
|
+
failAndCloseSocket(err);
|
|
358
373
|
});
|
|
359
374
|
this.addTrackedListener("error", ((error) => {
|
|
360
375
|
// First, raise an error event, to give clients a chance to observe error contents
|
|
@@ -362,7 +377,7 @@ class DocumentDeltaConnection extends telemetry_utils_1.EventEmitterWithErrorHan
|
|
|
362
377
|
const err = this.createErrorObject("error", error, error !== "Invalid namespace");
|
|
363
378
|
this.emit("error", err);
|
|
364
379
|
// Disconnect socket - required if happened before initial handshake
|
|
365
|
-
|
|
380
|
+
failAndCloseSocket(err);
|
|
366
381
|
}));
|
|
367
382
|
this.addConnectionListener("connect_document_error", ((error) => {
|
|
368
383
|
// If we sent a nonce and the server supports nonces, check that the nonces match
|
|
@@ -373,12 +388,12 @@ class DocumentDeltaConnection extends telemetry_utils_1.EventEmitterWithErrorHan
|
|
|
373
388
|
}
|
|
374
389
|
// This is not an socket.io error - it's Fluid protocol error.
|
|
375
390
|
// In this case fail connection and indicate that we were unable to create connection
|
|
376
|
-
|
|
391
|
+
failConnection(this.createErrorObject("connect_document_error", error));
|
|
377
392
|
}));
|
|
378
393
|
this.socket.emit("connect_document", connectMessage);
|
|
379
394
|
// Give extra 2 seconds for handshake on top of socket connection timeout
|
|
380
395
|
this.socketConnectionTimeout = setTimeout(() => {
|
|
381
|
-
|
|
396
|
+
failConnection(this.createErrorObject("orderingServiceHandshakeTimeout"));
|
|
382
397
|
}, timeout + 2000);
|
|
383
398
|
});
|
|
384
399
|
(0, common_utils_1.assert)(!this.disposed, 0x246 /* "checking consistency of socket & _disposed flags" */);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentDeltaConnection.js","sourceRoot":"","sources":["../src/documentDeltaConnection.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsD;AAKtD,+DAA0F;AAC1F,+EAW8C;AAE9C,qEAOyC;AAEzC,sFAAsF;AACtF,qDAA+D;AAE/D;;GAEG;AACH,MAAa,uBACT,SAAQ,+CAA6D;IAkErE;;;;;OAKG;IACH,YACuB,MAAc,EAC1B,UAAkB,EACzB,MAAwB,EACP,8BAAuC,KAAK;QAE7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AC,SAAS,CAAC,KAAK,EAAE,IAAA,qCAAmB,GAAE,CAAC,EAAE,CAAC;SAC/E;aAAM;YACH,OAAO,GAAG,IAAA,+CAA6B,EAAC,KAAK,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC;SAChE;QAED,MAAM,QAAQ,GAAG,IAAA,wCAAyB,EACtC,cAAc,OAAO,MAAM,OAAO,EAAE,EACpC,EAAE,QAAQ,EAAE,EACZ,EAAE,aAAa,EAAb,2BAAa,EAAE,CACpB,CAAC;QAEF,OAAO,QAAQ,CAAC;IACpB,CAAC;;AAjiBL,0DAkiBC;AA/hBmB,uCAAe,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AAEnE,mHAAmH;AACnH,oHAAoH;AACpG,6CAAqB,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport {\n IDocumentDeltaConnection,\n IDocumentDeltaConnectionEvents,\n} from \"@fluidframework/driver-definitions\";\nimport { createGenericNetworkError, IAnyDriverError } from \"@fluidframework/driver-utils\";\nimport {\n ConnectionMode,\n IClientConfiguration,\n IConnect,\n IConnected,\n IDocumentMessage,\n ISequencedDocumentMessage,\n ISignalClient,\n ISignalMessage,\n ITokenClaims,\n ScopeType,\n} from \"@fluidframework/protocol-definitions\";\nimport { IDisposable, ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport {\n ChildLogger,\n extractLogSafeErrorProperties,\n getCircularReplacer,\n loggerToMonitoringContext,\n MonitoringContext,\n EventEmitterWithErrorHandling,\n} from \"@fluidframework/telemetry-utils\";\nimport type { Socket } from \"socket.io-client\";\n// For now, this package is versioned and released in unison with the specific drivers\nimport { pkgVersion as driverVersion } from \"./packageVersion\";\n\n/**\n * Represents a connection to a stream of delta updates\n */\nexport class DocumentDeltaConnection\n extends EventEmitterWithErrorHandling<IDocumentDeltaConnectionEvents>\n implements IDocumentDeltaConnection, IDisposable {\n static readonly eventsToForward = [\"nack\", \"op\", \"signal\", \"pong\"];\n\n // WARNING: These are critical events that we can't miss, so registration for them has to be in place at all times!\n // Including before handshake is over, and after that (but before DeltaManager had a chance to put its own handlers)\n static readonly eventsAlwaysForwarded = [\"disconnect\", \"error\"];\n\n /**\n * Last known sequence number to ordering service at the time of connection\n * It may lap actual last sequence number (quite a bit, if container is very active).\n * But it's best information for client to figure out how far it is behind, at least\n * for \"read\" connections. \"write\" connections may use own \"join\" op to similar information,\n * that is likely to be more up-to-date.\n */\n public checkpointSequenceNumber: number | undefined;\n\n // Listen for ops sent before we receive a response to connect_document\n protected readonly queuedMessages: ISequencedDocumentMessage[] = [];\n protected readonly queuedSignals: ISignalMessage[] = [];\n\n /**\n * A flag to indicate whether we have our handler attached. If it's attached, we're queueing incoming ops\n * to later be retrieved via initialMessages.\n */\n private earlyOpHandlerAttached: boolean = false;\n\n private socketConnectionTimeout: ReturnType<typeof setTimeout> | undefined;\n\n private _details: IConnected | undefined;\n\n // Listeners only needed while the connection is in progress\n private readonly connectionListeners: Map<string, (...args: any[]) => void> = new Map();\n // Listeners used throughout the lifetime of the DocumentDeltaConnection\n private readonly trackedListeners: Map<string, (...args: any[]) => void> = new Map();\n\n protected get hasDetails(): boolean {\n return !!this._details;\n }\n\n public get disposed() {\n assert(this._disposed || this.socket.connected, 0x244 /* \"Socket is closed, but connection is not!\" */);\n return this._disposed;\n }\n\n /**\n * Flag to indicate whether the DocumentDeltaConnection is expected to still be capable of sending messages.\n * After disconnection, we flip this to prevent any stale messages from being emitted.\n */\n protected _disposed: boolean = false;\n private readonly mc: MonitoringContext;\n\n /**\n * @deprecated Implementors should manage their own logger or monitoring context\n */\n protected get logger(): ITelemetryLogger {\n return this.mc.logger;\n }\n\n public get details(): IConnected {\n if (!this._details) {\n throw new Error(\"Internal error: calling method before _details is initialized!\");\n }\n return this._details;\n }\n\n /**\n * @param socket - websocket to be used\n * @param documentId - ID of the document\n * @param logger - for reporting telemetry events\n * @param enableLongPollingDowngrades - allow connection to be downgraded to long-polling on websocket failure\n */\n protected constructor(\n protected readonly socket: Socket,\n public documentId: string,\n logger: ITelemetryLogger,\n private readonly enableLongPollingDowngrades: boolean = false,\n ) {\n super((name, error) => {\n logger.sendErrorEvent(\n {\n eventName: \"DeltaConnection:EventException\",\n name,\n },\n error);\n });\n\n this.mc = loggerToMonitoringContext(\n ChildLogger.create(logger, \"DeltaConnection\"));\n\n this.on(\"newListener\", (event, listener) => {\n assert(!this.disposed, 0x20a /* \"register for event on disposed object\" */);\n\n // Some events are already forwarded - see this.addTrackedListener() calls in initialize().\n if (DocumentDeltaConnection.eventsAlwaysForwarded.includes(event)) {\n assert(this.trackedListeners.has(event), 0x245 /* \"tracked listener\" */);\n return;\n }\n\n if (!DocumentDeltaConnection.eventsToForward.includes(event)) {\n throw new Error(`DocumentDeltaConnection: Registering for unknown event: ${event}`);\n }\n\n // Whenever listener is added, we should subscribe on same event on socket, so these two things\n // should be in sync. This currently assumes that nobody unregisters and registers back listeners,\n // and that there are no \"internal\" listeners installed (like \"error\" case we skip above)\n // Better flow might be to always unconditionally register all handlers on successful connection,\n // though some logic (naming assert in initialMessages getter) might need to be adjusted (it becomes noop)\n assert((this.listeners(event).length !== 0) === this.trackedListeners.has(event), 0x20b /* \"mismatch\" */);\n if (!this.trackedListeners.has(event)) {\n this.addTrackedListener(\n event,\n (...args: any[]) => {\n this.emit(event, ...args);\n });\n }\n });\n }\n\n /**\n * Get the ID of the client who is sending the message\n *\n * @returns the client ID\n */\n public get clientId(): string {\n return this.details.clientId;\n }\n\n /**\n * Get the mode of the client\n *\n * @returns the client mode\n */\n public get mode(): ConnectionMode {\n return this.details.mode;\n }\n\n /**\n * Get the claims of the client who is sending the message\n *\n * @returns client claims\n */\n public get claims(): ITokenClaims {\n return this.details.claims;\n }\n\n /**\n * Get whether or not this is an existing document\n *\n * @returns true if the document exists\n */\n public get existing(): boolean {\n return this.details.existing;\n }\n\n /**\n * Get the maximum size of a message before chunking is required\n *\n * @returns the maximum size of a message before chunking is required\n */\n public get maxMessageSize(): number {\n return this.details.serviceConfiguration.maxMessageSize;\n }\n\n /**\n * Semver of protocol being used with the service\n */\n public get version(): string {\n return this.details.version;\n }\n\n /**\n * Configuration details provided by the service\n */\n public get serviceConfiguration(): IClientConfiguration {\n return this.details.serviceConfiguration;\n }\n\n private checkNotClosed() {\n assert(!this.disposed, 0x20c /* \"connection disposed\" */);\n }\n\n /**\n * Get messages sent during the connection\n *\n * @returns messages sent during the connection\n */\n public get initialMessages(): ISequencedDocumentMessage[] {\n this.checkNotClosed();\n\n // If we call this when the earlyOpHandler is not attached, then the queuedMessages may not include the\n // latest ops. This could possibly indicate that initialMessages was called twice.\n assert(this.earlyOpHandlerAttached, 0x08e /* \"Potentially missed initial messages\" */);\n // We will lose ops and perf will tank as we need to go to storage to become current!\n assert(this.listeners(\"op\").length !== 0, 0x08f /* \"No op handler is setup!\" */);\n\n this.removeEarlyOpHandler();\n\n if (this.queuedMessages.length > 0) {\n // Some messages were queued.\n // add them to the list of initialMessages to be processed\n this.details.initialMessages.push(...this.queuedMessages);\n this.details.initialMessages.sort((a, b) => a.sequenceNumber - b.sequenceNumber);\n this.queuedMessages.length = 0;\n }\n return this.details.initialMessages;\n }\n\n /**\n * Get signals sent during the connection\n *\n * @returns signals sent during the connection\n */\n public get initialSignals(): ISignalMessage[] {\n this.checkNotClosed();\n assert(this.listeners(\"signal\").length !== 0, 0x090 /* \"No signal handler is setup!\" */);\n\n this.removeEarlySignalHandler();\n\n if (this.queuedSignals.length > 0) {\n // Some signals were queued.\n // add them to the list of initialSignals to be processed\n this.details.initialSignals.push(...this.queuedSignals);\n this.queuedSignals.length = 0;\n }\n return this.details.initialSignals;\n }\n\n /**\n * Get initial client list\n *\n * @returns initial client list sent during the connection\n */\n public get initialClients(): ISignalClient[] {\n this.checkNotClosed();\n return this.details.initialClients;\n }\n\n protected emitMessages(type: string, messages: IDocumentMessage[][]) {\n // Although the implementation here disconnects the socket and does not reuse it, other subclasses\n // (e.g. OdspDocumentDeltaConnection) may reuse the socket. In these cases, we need to avoid emitting\n // on the still-live socket.\n if (!this.disposed) {\n this.socket.emit(type, this.clientId, messages);\n }\n }\n\n protected submitCore(type: string, messages: IDocumentMessage[]) {\n this.emitMessages(type, [messages]);\n }\n\n /**\n * Submits a new delta operation to the server\n *\n * @param message - delta operation to submit\n */\n public submit(messages: IDocumentMessage[]): void {\n this.checkNotClosed();\n this.submitCore(\"submitOp\", messages);\n }\n\n /**\n * Submits a new signal to the server\n *\n * @param message - signal to submit\n */\n public submitSignal(message: IDocumentMessage): void {\n this.checkNotClosed();\n this.submitCore(\"submitSignal\", [message]);\n }\n\n /**\n * Disconnect from the websocket, and permanently disable this DocumentDeltaConnection.\n */\n public dispose() {\n this.disposeCore(\n false, // socketProtocolError\n createGenericNetworkError(\n // pre-0.58 error message: clientClosingConnection\n \"Client closing delta connection\", { canRetry: true }, { driverVersion }));\n }\n\n protected disposeCore(socketProtocolError: boolean, err: IAnyDriverError) {\n // Can't check this.disposed here, as we get here on socket closure,\n // so _disposed & socket.connected might be not in sync while processing\n // \"dispose\" event.\n if (this._disposed) {\n return;\n }\n\n // We set the disposed flag as a part of the contract for overriding the disconnect method. This is used by\n // DocumentDeltaConnection to determine if emitting messages (ops) on the socket is allowed, which is\n // important since OdspDocumentDeltaConnection reuses the socket rather than truly disconnecting it. Note that\n // OdspDocumentDeltaConnection may still send disconnect_document which is allowed; this is only intended\n // to prevent normal messages from being emitted.\n this._disposed = true;\n\n this.removeTrackedListeners();\n this.disconnect(socketProtocolError, err);\n }\n\n /**\n * Disconnect from the websocket.\n * @param socketProtocolError - true if error happened on socket / socket.io protocol level\n * (not on Fluid protocol level)\n * @param reason - reason for disconnect\n */\n protected disconnect(socketProtocolError: boolean, reason: IAnyDriverError) {\n this.socket.disconnect();\n }\n\n protected async initialize(connectMessage: IConnect, timeout: number) {\n this.socket.on(\"op\", this.earlyOpHandler);\n this.socket.on(\"signal\", this.earlySignalHandler);\n this.earlyOpHandlerAttached = true;\n\n // Socket.io's reconnect_attempt event is unreliable, so we track connect_error count instead.\n let internalSocketConnectionFailureCount: number = 0;\n const isInternalSocketReconnectionEnabled = (): boolean => this.socket.io.reconnection();\n const getMaxInternalSocketReconnectionAttempts = (): number => isInternalSocketReconnectionEnabled()\n ? this.socket.io.reconnectionAttempts()\n : 0;\n const getMaxAllowedInternalSocketConnectionFailures = (): number =>\n getMaxInternalSocketReconnectionAttempts() + 1;\n\n this._details = await new Promise<IConnected>((resolve, reject) => {\n const fail = (socketProtocolError: boolean, err: IAnyDriverError) => {\n this.disposeCore(socketProtocolError, err);\n reject(err);\n };\n\n // Listen for connection issues\n this.addConnectionListener(\"connect_error\", (error) => {\n internalSocketConnectionFailureCount++;\n let isWebSocketTransportError = false;\n try {\n const description = error?.description;\n if (description && typeof description === \"object\") {\n if (error.type === \"TransportError\") {\n isWebSocketTransportError = true;\n }\n // That's a WebSocket. Clear it as we can't log it.\n description.target = undefined;\n }\n } catch (_e) { }\n\n // Handle socket transport downgrading when not offline.\n if (\n isWebSocketTransportError &&\n this.enableLongPollingDowngrades &&\n this.socket.io.opts.transports?.[0] !== \"polling\") {\n // Downgrade transports to polling upgrade mechanism.\n this.socket.io.opts.transports = [\"polling\", \"websocket\"];\n // Don't alter reconnection behavior if already enabled.\n if (!isInternalSocketReconnectionEnabled()) {\n // Allow single reconnection attempt using polling upgrade mechanism.\n this.socket.io.reconnection(true);\n this.socket.io.reconnectionAttempts(1);\n }\n }\n\n // Allow built-in socket.io reconnection handling.\n if (isInternalSocketReconnectionEnabled() &&\n internalSocketConnectionFailureCount < getMaxAllowedInternalSocketConnectionFailures()) {\n // Reconnection is enabled and maximum reconnect attempts have not been reached.\n return;\n }\n\n fail(true, this.createErrorObject(\"connect_error\", error));\n });\n\n // Listen for timeouts\n this.addConnectionListener(\"connect_timeout\", () => {\n fail(true, this.createErrorObject(\"connect_timeout\"));\n });\n\n this.addConnectionListener(\"connect_document_success\", (response: IConnected) => {\n // If we sent a nonce and the server supports nonces, check that the nonces match\n if (connectMessage.nonce !== undefined &&\n response.nonce !== undefined &&\n response.nonce !== connectMessage.nonce) {\n return;\n }\n\n const requestedMode = connectMessage.mode;\n const actualMode = response.mode;\n const writingPermitted = response.claims.scopes.includes(ScopeType.DocWrite);\n\n if (writingPermitted) {\n // The only time we expect a mismatch in requested/actual is if we lack write permissions\n // In this case we will get \"read\", even if we requested \"write\"\n if (actualMode !== requestedMode) {\n fail(false, this.createErrorObject(\n \"connect_document_success\",\n \"Connected in a different mode than was requested\",\n false,\n ));\n return;\n }\n } else {\n if (actualMode === \"write\") {\n fail(false, this.createErrorObject(\n \"connect_document_success\",\n \"Connected in write mode without write permissions\",\n false,\n ));\n return;\n }\n }\n\n this.checkpointSequenceNumber = response.checkpointSequenceNumber;\n\n this.removeConnectionListeners();\n resolve(response);\n });\n\n // Socket can be disconnected while waiting for Fluid protocol messages\n // (connect_document_error / connect_document_success), as well as before DeltaManager\n // had a chance to register its handlers.\n this.addTrackedListener(\"disconnect\", (reason) => {\n const err = this.createErrorObject(\"disconnect\", reason);\n this.emit(\"disconnect\", err);\n fail(true, err);\n });\n\n this.addTrackedListener(\"error\", ((error) => {\n // First, raise an error event, to give clients a chance to observe error contents\n // This includes \"Invalid namespace\" error, which we consider critical (reconnecting will not help)\n const err = this.createErrorObject(\"error\", error, error !== \"Invalid namespace\");\n this.emit(\"error\", err);\n // Disconnect socket - required if happened before initial handshake\n fail(true, err);\n }));\n\n this.addConnectionListener(\"connect_document_error\", ((error) => {\n // If we sent a nonce and the server supports nonces, check that the nonces match\n if (connectMessage.nonce !== undefined &&\n error.nonce !== undefined &&\n error.nonce !== connectMessage.nonce) {\n return;\n }\n\n // This is not an socket.io error - it's Fluid protocol error.\n // In this case fail connection and indicate that we were unable to create connection\n fail(false, this.createErrorObject(\"connect_document_error\", error));\n }));\n\n this.socket.emit(\"connect_document\", connectMessage);\n\n // Give extra 2 seconds for handshake on top of socket connection timeout\n this.socketConnectionTimeout = setTimeout(() => {\n fail(false, this.createErrorObject(\"orderingServiceHandshakeTimeout\"));\n }, timeout + 2000);\n });\n\n assert(!this.disposed, 0x246 /* \"checking consistency of socket & _disposed flags\" */);\n }\n\n protected earlyOpHandler = (documentId: string, msgs: ISequencedDocumentMessage[]) => {\n this.queuedMessages.push(...msgs);\n };\n\n protected earlySignalHandler = (msg: ISignalMessage) => {\n this.queuedSignals.push(msg);\n };\n\n private removeEarlyOpHandler() {\n this.socket.removeListener(\"op\", this.earlyOpHandler);\n this.earlyOpHandlerAttached = false;\n }\n\n private removeEarlySignalHandler() {\n this.socket.removeListener(\"signal\", this.earlySignalHandler);\n }\n\n private addConnectionListener(event: string, listener: (...args: any[]) => void) {\n assert(!DocumentDeltaConnection.eventsAlwaysForwarded.includes(event),\n 0x247 /* \"Use addTrackedListener instead\" */);\n assert(!DocumentDeltaConnection.eventsToForward.includes(event),\n 0x248 /* \"should not subscribe to forwarded events\" */);\n this.socket.on(event, listener);\n assert(!this.connectionListeners.has(event), 0x20d /* \"double connection listener\" */);\n this.connectionListeners.set(event, listener);\n }\n\n protected addTrackedListener(event: string, listener: (...args: any[]) => void) {\n this.socket.on(event, listener);\n assert(!this.trackedListeners.has(event), 0x20e /* \"double tracked listener\" */);\n this.trackedListeners.set(event, listener);\n }\n\n private removeTrackedListeners() {\n for (const [event, listener] of this.trackedListeners.entries()) {\n this.socket.off(event, listener);\n }\n // removeTrackedListeners removes all listeners, including connection listeners\n this.removeConnectionListeners();\n\n this.removeEarlyOpHandler();\n this.removeEarlySignalHandler();\n\n this.trackedListeners.clear();\n }\n\n private removeConnectionListeners() {\n if (this.socketConnectionTimeout !== undefined) {\n clearTimeout(this.socketConnectionTimeout);\n }\n\n for (const [event, listener] of this.connectionListeners.entries()) {\n this.socket.off(event, listener);\n }\n this.connectionListeners.clear();\n }\n\n /**\n * Error raising for socket.io issues\n */\n protected createErrorObject(handler: string, error?: any, canRetry = true): IAnyDriverError {\n // Note: we suspect the incoming error object is either:\n // - a string: log it in the message (if not a string, it may contain PII but will print as [object Object])\n // - an Error object thrown by socket.io engine. Be careful with not recording PII!\n let message: string;\n if (error?.type === \"TransportError\") {\n // JSON.stringify drops Error.message\n const messagePrefix = (error?.message !== undefined)\n ? `${error.message}: `\n : \"\";\n\n // Websocket errors reported by engine.io-client.\n // They are Error objects with description containing WS error and description = \"TransportError\"\n // Please see https://github.com/socketio/engine.io-client/blob/7245b80/lib/transport.ts#L44,\n message = `${messagePrefix}${JSON.stringify(error, getCircularReplacer())}`;\n } else {\n message = extractLogSafeErrorProperties(error, true).message;\n }\n\n const errorObj = createGenericNetworkError(\n `socket.io (${handler}): ${message}`,\n { canRetry },\n { driverVersion },\n );\n\n return errorObj;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"documentDeltaConnection.js","sourceRoot":"","sources":["../src/documentDeltaConnection.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsD;AAMtD,+DAAyE;AACzE,+EAW8C;AAE9C,qEAOyC;AAEzC,sFAAsF;AACtF,qDAA+D;AAE/D;;GAEG;AACH,MAAa,uBACT,SAAQ,+CAA6D;IAkErE;;;;;OAKG;IACH,YACuB,MAAc,EAC1B,UAAkB,EACzB,MAAwB,EACP,8BAAuC,KAAK;QAE7D,KAAK,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;YAClB,MAAM,CAAC,cAAc,CACjB;gBACI,SAAS,EAAE,gCAAgC;gBAC3C,IAAI;aACP,EACD,KAAK,CAAC,CAAC;QACf,CAAC,CAAC,CAAC;QAZgB,WAAM,GAAN,MAAM,CAAQ;QAC1B,eAAU,GAAV,UAAU,CAAQ;QAER,gCAA2B,GAA3B,2BAA2B,CAAiB;QA3DjE,uEAAuE;QACpD,mBAAc,GAAgC,EAAE,CAAC;QACjD,kBAAa,GAAqB,EAAE,CAAC;QAExD;;;WAGG;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,wCAAyB,EACtC,cAAc,OAAO,MAAM,OAAO,EAAE,EACpC,EAAE,QAAQ,EAAE,EACZ,EAAE,aAAa,EAAb,2BAAa,EAAE,CACpB,CAAC;QAEF,OAAO,QAAQ,CAAC;IACpB,CAAC;;AAnjBL,0DAojBC;AAjjBmB,uCAAe,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AAEnE,mHAAmH;AACnH,oHAAoH;AACpG,6CAAqB,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport {\n IAnyDriverError,\n IDocumentDeltaConnection,\n IDocumentDeltaConnectionEvents,\n} from \"@fluidframework/driver-definitions\";\nimport { createGenericNetworkError } from \"@fluidframework/driver-utils\";\nimport {\n ConnectionMode,\n IClientConfiguration,\n IConnect,\n IConnected,\n IDocumentMessage,\n ISequencedDocumentMessage,\n ISignalClient,\n ISignalMessage,\n ITokenClaims,\n ScopeType,\n} from \"@fluidframework/protocol-definitions\";\nimport { IDisposable, ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport {\n ChildLogger,\n extractLogSafeErrorProperties,\n getCircularReplacer,\n loggerToMonitoringContext,\n MonitoringContext,\n EventEmitterWithErrorHandling,\n} from \"@fluidframework/telemetry-utils\";\nimport type { Socket } from \"socket.io-client\";\n// For now, this package is versioned and released in unison with the specific drivers\nimport { pkgVersion as driverVersion } from \"./packageVersion\";\n\n/**\n * Represents a connection to a stream of delta updates\n */\nexport class DocumentDeltaConnection\n extends EventEmitterWithErrorHandling<IDocumentDeltaConnectionEvents>\n implements IDocumentDeltaConnection, IDisposable {\n static readonly eventsToForward = [\"nack\", \"op\", \"signal\", \"pong\"];\n\n // WARNING: These are critical events that we can't miss, so registration for them has to be in place at all times!\n // Including before handshake is over, and after that (but before DeltaManager had a chance to put its own handlers)\n static readonly eventsAlwaysForwarded = [\"disconnect\", \"error\"];\n\n /**\n * Last known sequence number to ordering service at the time of connection\n * It may lap actual last sequence number (quite a bit, if container is very active).\n * But it's best information for client to figure out how far it is behind, at least\n * for \"read\" connections. \"write\" connections may use own \"join\" op to similar information,\n * that is likely to be more up-to-date.\n */\n public checkpointSequenceNumber: number | undefined;\n\n // Listen for ops sent before we receive a response to connect_document\n protected readonly queuedMessages: ISequencedDocumentMessage[] = [];\n protected readonly queuedSignals: ISignalMessage[] = [];\n\n /**\n * A flag to indicate whether we have our handler attached. If it's attached, we're queueing incoming ops\n * to later be retrieved via initialMessages.\n */\n private earlyOpHandlerAttached: boolean = false;\n\n private socketConnectionTimeout: ReturnType<typeof setTimeout> | undefined;\n\n private _details: IConnected | undefined;\n\n // Listeners only needed while the connection is in progress\n private readonly connectionListeners: Map<string, (...args: any[]) => void> = new Map();\n // Listeners used throughout the lifetime of the DocumentDeltaConnection\n private readonly trackedListeners: Map<string, (...args: any[]) => void> = new Map();\n\n protected get hasDetails(): boolean {\n return !!this._details;\n }\n\n public get disposed() {\n assert(this._disposed || this.socket.connected, 0x244 /* \"Socket is closed, but connection is not!\" */);\n return this._disposed;\n }\n\n /**\n * Flag to indicate whether the DocumentDeltaConnection is expected to still be capable of sending messages.\n * After disconnection, we flip this to prevent any stale messages from being emitted.\n */\n protected _disposed: boolean = false;\n private readonly mc: MonitoringContext;\n\n /**\n * @deprecated Implementors should manage their own logger or monitoring context\n */\n protected get logger(): ITelemetryLogger {\n return this.mc.logger;\n }\n\n public get details(): IConnected {\n if (!this._details) {\n throw new Error(\"Internal error: calling method before _details is initialized!\");\n }\n return this._details;\n }\n\n /**\n * @param socket - websocket to be used\n * @param documentId - ID of the document\n * @param logger - for reporting telemetry events\n * @param enableLongPollingDowngrades - allow connection to be downgraded to long-polling on websocket failure\n */\n protected constructor(\n protected readonly socket: Socket,\n public documentId: string,\n logger: ITelemetryLogger,\n private readonly enableLongPollingDowngrades: boolean = false,\n ) {\n super((name, error) => {\n logger.sendErrorEvent(\n {\n eventName: \"DeltaConnection:EventException\",\n name,\n },\n error);\n });\n\n this.mc = loggerToMonitoringContext(\n ChildLogger.create(logger, \"DeltaConnection\"));\n\n this.on(\"newListener\", (event, listener) => {\n assert(!this.disposed, 0x20a /* \"register for event on disposed object\" */);\n\n // Some events are already forwarded - see this.addTrackedListener() calls in initialize().\n if (DocumentDeltaConnection.eventsAlwaysForwarded.includes(event)) {\n assert(this.trackedListeners.has(event), 0x245 /* \"tracked listener\" */);\n return;\n }\n\n if (!DocumentDeltaConnection.eventsToForward.includes(event)) {\n throw new Error(`DocumentDeltaConnection: Registering for unknown event: ${event}`);\n }\n\n // Whenever listener is added, we should subscribe on same event on socket, so these two things\n // should be in sync. This currently assumes that nobody unregisters and registers back listeners,\n // and that there are no \"internal\" listeners installed (like \"error\" case we skip above)\n // Better flow might be to always unconditionally register all handlers on successful connection,\n // though some logic (naming assert in initialMessages getter) might need to be adjusted (it becomes noop)\n assert((this.listeners(event).length !== 0) === this.trackedListeners.has(event), 0x20b /* \"mismatch\" */);\n if (!this.trackedListeners.has(event)) {\n this.addTrackedListener(\n event,\n (...args: any[]) => {\n this.emit(event, ...args);\n });\n }\n });\n }\n\n /**\n * Get the ID of the client who is sending the message\n *\n * @returns the client ID\n */\n public get clientId(): string {\n return this.details.clientId;\n }\n\n /**\n * Get the mode of the client\n *\n * @returns the client mode\n */\n public get mode(): ConnectionMode {\n return this.details.mode;\n }\n\n /**\n * Get the claims of the client who is sending the message\n *\n * @returns client claims\n */\n public get claims(): ITokenClaims {\n return this.details.claims;\n }\n\n /**\n * Get whether or not this is an existing document\n *\n * @returns true if the document exists\n */\n public get existing(): boolean {\n return this.details.existing;\n }\n\n /**\n * Get the maximum size of a message before chunking is required\n *\n * @returns the maximum size of a message before chunking is required\n */\n public get maxMessageSize(): number {\n return this.details.serviceConfiguration.maxMessageSize;\n }\n\n /**\n * Semver of protocol being used with the service\n */\n public get version(): string {\n return this.details.version;\n }\n\n /**\n * Configuration details provided by the service\n */\n public get serviceConfiguration(): IClientConfiguration {\n return this.details.serviceConfiguration;\n }\n\n private checkNotClosed() {\n assert(!this.disposed, 0x20c /* \"connection disposed\" */);\n }\n\n /**\n * Get messages sent during the connection\n *\n * @returns messages sent during the connection\n */\n public get initialMessages(): ISequencedDocumentMessage[] {\n this.checkNotClosed();\n\n // If we call this when the earlyOpHandler is not attached, then the queuedMessages may not include the\n // latest ops. This could possibly indicate that initialMessages was called twice.\n assert(this.earlyOpHandlerAttached, 0x08e /* \"Potentially missed initial messages\" */);\n // We will lose ops and perf will tank as we need to go to storage to become current!\n assert(this.listeners(\"op\").length !== 0, 0x08f /* \"No op handler is setup!\" */);\n\n this.removeEarlyOpHandler();\n\n if (this.queuedMessages.length > 0) {\n // Some messages were queued.\n // add them to the list of initialMessages to be processed\n this.details.initialMessages.push(...this.queuedMessages);\n this.details.initialMessages.sort((a, b) => a.sequenceNumber - b.sequenceNumber);\n this.queuedMessages.length = 0;\n }\n return this.details.initialMessages;\n }\n\n /**\n * Get signals sent during the connection\n *\n * @returns signals sent during the connection\n */\n public get initialSignals(): ISignalMessage[] {\n this.checkNotClosed();\n assert(this.listeners(\"signal\").length !== 0, 0x090 /* \"No signal handler is setup!\" */);\n\n this.removeEarlySignalHandler();\n\n if (this.queuedSignals.length > 0) {\n // Some signals were queued.\n // add them to the list of initialSignals to be processed\n this.details.initialSignals.push(...this.queuedSignals);\n this.queuedSignals.length = 0;\n }\n return this.details.initialSignals;\n }\n\n /**\n * Get initial client list\n *\n * @returns initial client list sent during the connection\n */\n public get initialClients(): ISignalClient[] {\n this.checkNotClosed();\n return this.details.initialClients;\n }\n\n protected emitMessages(type: string, messages: IDocumentMessage[][]) {\n // Although the implementation here disconnects the socket and does not reuse it, other subclasses\n // (e.g. OdspDocumentDeltaConnection) may reuse the socket. In these cases, we need to avoid emitting\n // on the still-live socket.\n if (!this.disposed) {\n this.socket.emit(type, this.clientId, messages);\n }\n }\n\n protected submitCore(type: string, messages: IDocumentMessage[]) {\n this.emitMessages(type, [messages]);\n }\n\n /**\n * Submits a new delta operation to the server\n *\n * @param message - delta operation to submit\n */\n public submit(messages: IDocumentMessage[]): void {\n this.checkNotClosed();\n this.submitCore(\"submitOp\", messages);\n }\n\n /**\n * Submits a new signal to the server\n *\n * @param message - signal to submit\n */\n public submitSignal(message: IDocumentMessage): void {\n this.checkNotClosed();\n this.submitCore(\"submitSignal\", [message]);\n }\n\n /**\n * Disconnect from the websocket and close the websocket too.\n */\n protected closeSocket(error: IAnyDriverError) {\n this.disconnect(error);\n }\n\n /**\n * Disconnect from the websocket, and permanently disable this DocumentDeltaConnection and close the socket.\n * However the OdspDocumentDeltaConnection differ in dispose as in there we don't close the socket. There is no\n * multiplexing here, so we need to close the socket here.\n */\n public dispose() {\n this.disconnect(createGenericNetworkError(\n // pre-0.58 error message: clientClosingConnection\n \"Client closing delta connection\", { canRetry: true }, { driverVersion }),\n );\n }\n\n protected disconnect(err: IAnyDriverError) {\n // Can't check this.disposed here, as we get here on socket closure,\n // so _disposed & socket.connected might be not in sync while processing\n // \"dispose\" event.\n if (this._disposed) {\n return;\n }\n\n // We set the disposed flag as a part of the contract for overriding the disconnect method. This is used by\n // DocumentDeltaConnection to determine if emitting messages (ops) on the socket is allowed, which is\n // important since OdspDocumentDeltaConnection reuses the socket rather than truly disconnecting it. Note that\n // OdspDocumentDeltaConnection may still send disconnect_document which is allowed; this is only intended\n // to prevent normal messages from being emitted.\n this._disposed = true;\n\n // Let user of connection object know about disconnect. This has to happen in betwee setting _disposed and\n // removing all listeners!\n this.emit(\"disconnect\", err);\n\n // user of DeltaConnection should have processed \"disconnect\" event and removed all listeners. Not clear\n // if we want to enforce that, as some users (like LocalDocumentService) do not unregister any handlers\n // assert(this.listenerCount(\"disconnect\") === 0, \"'disconnect` events should be processed synchronously\");\n\n this.removeTrackedListeners();\n this.disconnectCore();\n }\n\n /**\n * Disconnect from the websocket.\n * @param reason - reason for disconnect\n */\n protected disconnectCore() {\n this.socket.disconnect();\n }\n\n protected async initialize(connectMessage: IConnect, timeout: number) {\n this.socket.on(\"op\", this.earlyOpHandler);\n this.socket.on(\"signal\", this.earlySignalHandler);\n this.earlyOpHandlerAttached = true;\n\n // Socket.io's reconnect_attempt event is unreliable, so we track connect_error count instead.\n let internalSocketConnectionFailureCount: number = 0;\n const isInternalSocketReconnectionEnabled = (): boolean => this.socket.io.reconnection();\n const getMaxInternalSocketReconnectionAttempts = (): number => isInternalSocketReconnectionEnabled()\n ? this.socket.io.reconnectionAttempts()\n : 0;\n const getMaxAllowedInternalSocketConnectionFailures = (): number =>\n getMaxInternalSocketReconnectionAttempts() + 1;\n\n this._details = await new Promise<IConnected>((resolve, reject) => {\n const failAndCloseSocket = (err: IAnyDriverError) => {\n this.closeSocket(err);\n reject(err);\n };\n\n const failConnection = (err: IAnyDriverError) => {\n this.disconnect(err);\n reject(err);\n };\n // Listen for connection issues\n this.addConnectionListener(\"connect_error\", (error) => {\n internalSocketConnectionFailureCount++;\n let isWebSocketTransportError = false;\n try {\n const description = error?.description;\n if (description && typeof description === \"object\") {\n if (error.type === \"TransportError\") {\n isWebSocketTransportError = true;\n }\n // That's a WebSocket. Clear it as we can't log it.\n description.target = undefined;\n }\n } catch (_e) { }\n\n // Handle socket transport downgrading when not offline.\n if (\n isWebSocketTransportError &&\n this.enableLongPollingDowngrades &&\n this.socket.io.opts.transports?.[0] !== \"polling\") {\n // Downgrade transports to polling upgrade mechanism.\n this.socket.io.opts.transports = [\"polling\", \"websocket\"];\n // Don't alter reconnection behavior if already enabled.\n if (!isInternalSocketReconnectionEnabled()) {\n // Allow single reconnection attempt using polling upgrade mechanism.\n this.socket.io.reconnection(true);\n this.socket.io.reconnectionAttempts(1);\n }\n }\n\n // Allow built-in socket.io reconnection handling.\n if (isInternalSocketReconnectionEnabled() &&\n internalSocketConnectionFailureCount < getMaxAllowedInternalSocketConnectionFailures()) {\n // Reconnection is enabled and maximum reconnect attempts have not been reached.\n return;\n }\n\n failAndCloseSocket(this.createErrorObject(\"connect_error\", error));\n });\n\n // Listen for timeouts\n this.addConnectionListener(\"connect_timeout\", () => {\n failAndCloseSocket(this.createErrorObject(\"connect_timeout\"));\n });\n\n this.addConnectionListener(\"connect_document_success\", (response: IConnected) => {\n // If we sent a nonce and the server supports nonces, check that the nonces match\n if (connectMessage.nonce !== undefined &&\n response.nonce !== undefined &&\n response.nonce !== connectMessage.nonce) {\n return;\n }\n\n const requestedMode = connectMessage.mode;\n const actualMode = response.mode;\n const writingPermitted = response.claims.scopes.includes(ScopeType.DocWrite);\n\n if (writingPermitted) {\n // The only time we expect a mismatch in requested/actual is if we lack write permissions\n // In this case we will get \"read\", even if we requested \"write\"\n if (actualMode !== requestedMode) {\n failConnection(this.createErrorObject(\n \"connect_document_success\",\n \"Connected in a different mode than was requested\",\n false,\n ));\n return;\n }\n } else {\n if (actualMode === \"write\") {\n failConnection(this.createErrorObject(\n \"connect_document_success\",\n \"Connected in write mode without write permissions\",\n false,\n ));\n return;\n }\n }\n\n this.checkpointSequenceNumber = response.checkpointSequenceNumber;\n\n this.removeConnectionListeners();\n resolve(response);\n });\n\n // Socket can be disconnected while waiting for Fluid protocol messages\n // (connect_document_error / connect_document_success), as well as before DeltaManager\n // had a chance to register its handlers.\n this.addTrackedListener(\"disconnect\", (reason) => {\n const err = this.createErrorObject(\"disconnect\", reason);\n this.emit(\"disconnect\", err);\n failAndCloseSocket(err);\n });\n\n this.addTrackedListener(\"error\", ((error) => {\n // First, raise an error event, to give clients a chance to observe error contents\n // This includes \"Invalid namespace\" error, which we consider critical (reconnecting will not help)\n const err = this.createErrorObject(\"error\", error, error !== \"Invalid namespace\");\n this.emit(\"error\", err);\n // Disconnect socket - required if happened before initial handshake\n failAndCloseSocket(err);\n }));\n\n this.addConnectionListener(\"connect_document_error\", ((error) => {\n // If we sent a nonce and the server supports nonces, check that the nonces match\n if (connectMessage.nonce !== undefined &&\n error.nonce !== undefined &&\n error.nonce !== connectMessage.nonce) {\n return;\n }\n\n // This is not an socket.io error - it's Fluid protocol error.\n // In this case fail connection and indicate that we were unable to create connection\n failConnection(this.createErrorObject(\"connect_document_error\", error));\n }));\n\n this.socket.emit(\"connect_document\", connectMessage);\n\n // Give extra 2 seconds for handshake on top of socket connection timeout\n this.socketConnectionTimeout = setTimeout(() => {\n failConnection(this.createErrorObject(\"orderingServiceHandshakeTimeout\"));\n }, timeout + 2000);\n });\n\n assert(!this.disposed, 0x246 /* \"checking consistency of socket & _disposed flags\" */);\n }\n\n protected earlyOpHandler = (documentId: string, msgs: ISequencedDocumentMessage[]) => {\n this.queuedMessages.push(...msgs);\n };\n\n protected earlySignalHandler = (msg: ISignalMessage) => {\n this.queuedSignals.push(msg);\n };\n\n private removeEarlyOpHandler() {\n this.socket.removeListener(\"op\", this.earlyOpHandler);\n this.earlyOpHandlerAttached = false;\n }\n\n private removeEarlySignalHandler() {\n this.socket.removeListener(\"signal\", this.earlySignalHandler);\n }\n\n private addConnectionListener(event: string, listener: (...args: any[]) => void) {\n assert(!DocumentDeltaConnection.eventsAlwaysForwarded.includes(event),\n 0x247 /* \"Use addTrackedListener instead\" */);\n assert(!DocumentDeltaConnection.eventsToForward.includes(event),\n 0x248 /* \"should not subscribe to forwarded events\" */);\n this.socket.on(event, listener);\n assert(!this.connectionListeners.has(event), 0x20d /* \"double connection listener\" */);\n this.connectionListeners.set(event, listener);\n }\n\n protected addTrackedListener(event: string, listener: (...args: any[]) => void) {\n this.socket.on(event, listener);\n assert(!this.trackedListeners.has(event), 0x20e /* \"double tracked listener\" */);\n this.trackedListeners.set(event, listener);\n }\n\n private removeTrackedListeners() {\n for (const [event, listener] of this.trackedListeners.entries()) {\n this.socket.off(event, listener);\n }\n // removeTrackedListeners removes all listeners, including connection listeners\n this.removeConnectionListeners();\n\n this.removeEarlyOpHandler();\n this.removeEarlySignalHandler();\n\n this.trackedListeners.clear();\n }\n\n private removeConnectionListeners() {\n if (this.socketConnectionTimeout !== undefined) {\n clearTimeout(this.socketConnectionTimeout);\n }\n\n for (const [event, listener] of this.connectionListeners.entries()) {\n this.socket.off(event, listener);\n }\n this.connectionListeners.clear();\n }\n\n /**\n * Error raising for socket.io issues\n */\n protected createErrorObject(handler: string, error?: any, canRetry = true): IAnyDriverError {\n // Note: we suspect the incoming error object is either:\n // - a string: log it in the message (if not a string, it may contain PII but will print as [object Object])\n // - an Error object thrown by socket.io engine. Be careful with not recording PII!\n let message: string;\n if (error?.type === \"TransportError\") {\n // JSON.stringify drops Error.message\n const messagePrefix = (error?.message !== undefined)\n ? `${error.message}: `\n : \"\";\n\n // Websocket errors reported by engine.io-client.\n // They are Error objects with description containing WS error and description = \"TransportError\"\n // Please see https://github.com/socketio/engine.io-client/blob/7245b80/lib/transport.ts#L44,\n message = `${messagePrefix}${JSON.stringify(error, getCircularReplacer())}`;\n } else {\n message = extractLogSafeErrorProperties(error, true).message;\n }\n\n const errorObj = createGenericNetworkError(\n `socket.io (${handler}): ${message}`,\n { canRetry },\n { driverVersion },\n );\n\n return errorObj;\n }\n}\n"]}
|
package/dist/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/driver-base";
|
|
8
|
-
export declare const pkgVersion = "2.0.0-internal.
|
|
8
|
+
export declare const pkgVersion = "2.0.0-internal.2.0.1";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluidframework/driver-base";
|
|
11
|
-
exports.pkgVersion = "2.0.0-internal.
|
|
11
|
+
exports.pkgVersion = "2.0.0-internal.2.0.1";
|
|
12
12
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,6BAA6B,CAAC;AACxC,QAAA,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/driver-base\";\nexport const pkgVersion = \"2.0.0-internal.
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,6BAA6B,CAAC;AACxC,QAAA,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/driver-base\";\nexport const pkgVersion = \"2.0.0-internal.2.0.1\";\n"]}
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { IDocumentDeltaConnection, IDocumentDeltaConnectionEvents } from "@fluidframework/driver-definitions";
|
|
6
|
-
import { IAnyDriverError } from "@fluidframework/driver-utils";
|
|
5
|
+
import { IAnyDriverError, IDocumentDeltaConnection, IDocumentDeltaConnectionEvents } from "@fluidframework/driver-definitions";
|
|
7
6
|
import { ConnectionMode, IClientConfiguration, IConnect, IConnected, IDocumentMessage, ISequencedDocumentMessage, ISignalClient, ISignalMessage, ITokenClaims } from "@fluidframework/protocol-definitions";
|
|
8
7
|
import { IDisposable, ITelemetryLogger } from "@fluidframework/common-definitions";
|
|
9
8
|
import { EventEmitterWithErrorHandling } from "@fluidframework/telemetry-utils";
|
|
@@ -128,17 +127,21 @@ export declare class DocumentDeltaConnection extends EventEmitterWithErrorHandli
|
|
|
128
127
|
*/
|
|
129
128
|
submitSignal(message: IDocumentMessage): void;
|
|
130
129
|
/**
|
|
131
|
-
* Disconnect from the websocket
|
|
130
|
+
* Disconnect from the websocket and close the websocket too.
|
|
131
|
+
*/
|
|
132
|
+
protected closeSocket(error: IAnyDriverError): void;
|
|
133
|
+
/**
|
|
134
|
+
* Disconnect from the websocket, and permanently disable this DocumentDeltaConnection and close the socket.
|
|
135
|
+
* However the OdspDocumentDeltaConnection differ in dispose as in there we don't close the socket. There is no
|
|
136
|
+
* multiplexing here, so we need to close the socket here.
|
|
132
137
|
*/
|
|
133
138
|
dispose(): void;
|
|
134
|
-
protected
|
|
139
|
+
protected disconnect(err: IAnyDriverError): void;
|
|
135
140
|
/**
|
|
136
141
|
* Disconnect from the websocket.
|
|
137
|
-
* @param socketProtocolError - true if error happened on socket / socket.io protocol level
|
|
138
|
-
* (not on Fluid protocol level)
|
|
139
142
|
* @param reason - reason for disconnect
|
|
140
143
|
*/
|
|
141
|
-
protected
|
|
144
|
+
protected disconnectCore(): void;
|
|
142
145
|
protected initialize(connectMessage: IConnect, timeout: number): Promise<void>;
|
|
143
146
|
protected earlyOpHandler: (documentId: string, msgs: ISequencedDocumentMessage[]) => void;
|
|
144
147
|
protected earlySignalHandler: (msg: ISignalMessage) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentDeltaConnection.d.ts","sourceRoot":"","sources":["../src/documentDeltaConnection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACH,wBAAwB,EACxB,8BAA8B,EACjC,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"documentDeltaConnection.d.ts","sourceRoot":"","sources":["../src/documentDeltaConnection.ts"],"names":[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,OAAO;IAOd,SAAS,CAAC,UAAU,CAAC,GAAG,EAAE,eAAe;IA2BzC;;;OAGG;IACH,SAAS,CAAC,cAAc;cAIR,UAAU,CAAC,cAAc,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM;IAuJpE,SAAS,CAAC,cAAc,eAAgB,MAAM,QAAQ,yBAAyB,EAAE,UAE/E;IAEF,SAAS,CAAC,kBAAkB,QAAS,cAAc,UAEjD;IAEF,OAAO,CAAC,oBAAoB;IAK5B,OAAO,CAAC,wBAAwB;IAIhC,OAAO,CAAC,qBAAqB;IAU7B,SAAS,CAAC,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI;IAM9E,OAAO,CAAC,sBAAsB;IAa9B,OAAO,CAAC,yBAAyB;IAWjC;;OAEG;IACH,SAAS,CAAC,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG,EAAE,QAAQ,UAAO,GAAG,eAAe;CA2B9F"}
|
|
@@ -227,15 +227,22 @@ export class DocumentDeltaConnection extends EventEmitterWithErrorHandling {
|
|
|
227
227
|
this.submitCore("submitSignal", [message]);
|
|
228
228
|
}
|
|
229
229
|
/**
|
|
230
|
-
* Disconnect from the websocket
|
|
230
|
+
* Disconnect from the websocket and close the websocket too.
|
|
231
|
+
*/
|
|
232
|
+
closeSocket(error) {
|
|
233
|
+
this.disconnect(error);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Disconnect from the websocket, and permanently disable this DocumentDeltaConnection and close the socket.
|
|
237
|
+
* However the OdspDocumentDeltaConnection differ in dispose as in there we don't close the socket. There is no
|
|
238
|
+
* multiplexing here, so we need to close the socket here.
|
|
231
239
|
*/
|
|
232
240
|
dispose() {
|
|
233
|
-
this.
|
|
234
|
-
createGenericNetworkError(
|
|
241
|
+
this.disconnect(createGenericNetworkError(
|
|
235
242
|
// pre-0.58 error message: clientClosingConnection
|
|
236
243
|
"Client closing delta connection", { canRetry: true }, { driverVersion }));
|
|
237
244
|
}
|
|
238
|
-
|
|
245
|
+
disconnect(err) {
|
|
239
246
|
// Can't check this.disposed here, as we get here on socket closure,
|
|
240
247
|
// so _disposed & socket.connected might be not in sync while processing
|
|
241
248
|
// "dispose" event.
|
|
@@ -248,16 +255,20 @@ export class DocumentDeltaConnection extends EventEmitterWithErrorHandling {
|
|
|
248
255
|
// OdspDocumentDeltaConnection may still send disconnect_document which is allowed; this is only intended
|
|
249
256
|
// to prevent normal messages from being emitted.
|
|
250
257
|
this._disposed = true;
|
|
258
|
+
// Let user of connection object know about disconnect. This has to happen in betwee setting _disposed and
|
|
259
|
+
// removing all listeners!
|
|
260
|
+
this.emit("disconnect", err);
|
|
261
|
+
// user of DeltaConnection should have processed "disconnect" event and removed all listeners. Not clear
|
|
262
|
+
// if we want to enforce that, as some users (like LocalDocumentService) do not unregister any handlers
|
|
263
|
+
// assert(this.listenerCount("disconnect") === 0, "'disconnect` events should be processed synchronously");
|
|
251
264
|
this.removeTrackedListeners();
|
|
252
|
-
this.
|
|
265
|
+
this.disconnectCore();
|
|
253
266
|
}
|
|
254
267
|
/**
|
|
255
268
|
* Disconnect from the websocket.
|
|
256
|
-
* @param socketProtocolError - true if error happened on socket / socket.io protocol level
|
|
257
|
-
* (not on Fluid protocol level)
|
|
258
269
|
* @param reason - reason for disconnect
|
|
259
270
|
*/
|
|
260
|
-
|
|
271
|
+
disconnectCore() {
|
|
261
272
|
this.socket.disconnect();
|
|
262
273
|
}
|
|
263
274
|
async initialize(connectMessage, timeout) {
|
|
@@ -272,8 +283,12 @@ export class DocumentDeltaConnection extends EventEmitterWithErrorHandling {
|
|
|
272
283
|
: 0;
|
|
273
284
|
const getMaxAllowedInternalSocketConnectionFailures = () => getMaxInternalSocketReconnectionAttempts() + 1;
|
|
274
285
|
this._details = await new Promise((resolve, reject) => {
|
|
275
|
-
const
|
|
276
|
-
this.
|
|
286
|
+
const failAndCloseSocket = (err) => {
|
|
287
|
+
this.closeSocket(err);
|
|
288
|
+
reject(err);
|
|
289
|
+
};
|
|
290
|
+
const failConnection = (err) => {
|
|
291
|
+
this.disconnect(err);
|
|
277
292
|
reject(err);
|
|
278
293
|
};
|
|
279
294
|
// Listen for connection issues
|
|
@@ -311,11 +326,11 @@ export class DocumentDeltaConnection extends EventEmitterWithErrorHandling {
|
|
|
311
326
|
// Reconnection is enabled and maximum reconnect attempts have not been reached.
|
|
312
327
|
return;
|
|
313
328
|
}
|
|
314
|
-
|
|
329
|
+
failAndCloseSocket(this.createErrorObject("connect_error", error));
|
|
315
330
|
});
|
|
316
331
|
// Listen for timeouts
|
|
317
332
|
this.addConnectionListener("connect_timeout", () => {
|
|
318
|
-
|
|
333
|
+
failAndCloseSocket(this.createErrorObject("connect_timeout"));
|
|
319
334
|
});
|
|
320
335
|
this.addConnectionListener("connect_document_success", (response) => {
|
|
321
336
|
// If we sent a nonce and the server supports nonces, check that the nonces match
|
|
@@ -331,13 +346,13 @@ export class DocumentDeltaConnection extends EventEmitterWithErrorHandling {
|
|
|
331
346
|
// The only time we expect a mismatch in requested/actual is if we lack write permissions
|
|
332
347
|
// In this case we will get "read", even if we requested "write"
|
|
333
348
|
if (actualMode !== requestedMode) {
|
|
334
|
-
|
|
349
|
+
failConnection(this.createErrorObject("connect_document_success", "Connected in a different mode than was requested", false));
|
|
335
350
|
return;
|
|
336
351
|
}
|
|
337
352
|
}
|
|
338
353
|
else {
|
|
339
354
|
if (actualMode === "write") {
|
|
340
|
-
|
|
355
|
+
failConnection(this.createErrorObject("connect_document_success", "Connected in write mode without write permissions", false));
|
|
341
356
|
return;
|
|
342
357
|
}
|
|
343
358
|
}
|
|
@@ -351,7 +366,7 @@ export class DocumentDeltaConnection extends EventEmitterWithErrorHandling {
|
|
|
351
366
|
this.addTrackedListener("disconnect", (reason) => {
|
|
352
367
|
const err = this.createErrorObject("disconnect", reason);
|
|
353
368
|
this.emit("disconnect", err);
|
|
354
|
-
|
|
369
|
+
failAndCloseSocket(err);
|
|
355
370
|
});
|
|
356
371
|
this.addTrackedListener("error", ((error) => {
|
|
357
372
|
// First, raise an error event, to give clients a chance to observe error contents
|
|
@@ -359,7 +374,7 @@ export class DocumentDeltaConnection extends EventEmitterWithErrorHandling {
|
|
|
359
374
|
const err = this.createErrorObject("error", error, error !== "Invalid namespace");
|
|
360
375
|
this.emit("error", err);
|
|
361
376
|
// Disconnect socket - required if happened before initial handshake
|
|
362
|
-
|
|
377
|
+
failAndCloseSocket(err);
|
|
363
378
|
}));
|
|
364
379
|
this.addConnectionListener("connect_document_error", ((error) => {
|
|
365
380
|
// If we sent a nonce and the server supports nonces, check that the nonces match
|
|
@@ -370,12 +385,12 @@ export class DocumentDeltaConnection extends EventEmitterWithErrorHandling {
|
|
|
370
385
|
}
|
|
371
386
|
// This is not an socket.io error - it's Fluid protocol error.
|
|
372
387
|
// In this case fail connection and indicate that we were unable to create connection
|
|
373
|
-
|
|
388
|
+
failConnection(this.createErrorObject("connect_document_error", error));
|
|
374
389
|
}));
|
|
375
390
|
this.socket.emit("connect_document", connectMessage);
|
|
376
391
|
// Give extra 2 seconds for handshake on top of socket connection timeout
|
|
377
392
|
this.socketConnectionTimeout = setTimeout(() => {
|
|
378
|
-
|
|
393
|
+
failConnection(this.createErrorObject("orderingServiceHandshakeTimeout"));
|
|
379
394
|
}, timeout + 2000);
|
|
380
395
|
});
|
|
381
396
|
assert(!this.disposed, 0x246 /* "checking consistency of socket & _disposed flags" */);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentDeltaConnection.js","sourceRoot":"","sources":["../src/documentDeltaConnection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAKtD,OAAO,EAAE,yBAAyB,EAAmB,MAAM,8BAA8B,CAAC;AAC1F,OAAO,EAUH,SAAS,GACZ,MAAM,sCAAsC,CAAC;AAE9C,OAAO,E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AAO,MAAK,SAAS,CAAC;gBAChD,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,IAAI;gBACtB,CAAC,CAAC,EAAE,CAAC;YAET,iDAAiD;YACjD,iGAAiG;YACjG,6FAA6F;YAC7F,OAAO,GAAG,GAAG,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,mBAAmB,EAAE,CAAC,EAAE,CAAC;SAC/E;aAAM;YACH,OAAO,GAAG,6BAA6B,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC;SAChE;QAED,MAAM,QAAQ,GAAG,yBAAyB,CACtC,cAAc,OAAO,MAAM,OAAO,EAAE,EACpC,EAAE,QAAQ,EAAE,EACZ,EAAE,aAAa,EAAE,CACpB,CAAC;QAEF,OAAO,QAAQ,CAAC;IACpB,CAAC;;AA9hBe,uCAAe,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AAEnE,mHAAmH;AACnH,oHAAoH;AACpG,6CAAqB,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport {\n IDocumentDeltaConnection,\n IDocumentDeltaConnectionEvents,\n} from \"@fluidframework/driver-definitions\";\nimport { createGenericNetworkError, IAnyDriverError } from \"@fluidframework/driver-utils\";\nimport {\n ConnectionMode,\n IClientConfiguration,\n IConnect,\n IConnected,\n IDocumentMessage,\n ISequencedDocumentMessage,\n ISignalClient,\n ISignalMessage,\n ITokenClaims,\n ScopeType,\n} from \"@fluidframework/protocol-definitions\";\nimport { IDisposable, ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport {\n ChildLogger,\n extractLogSafeErrorProperties,\n getCircularReplacer,\n loggerToMonitoringContext,\n MonitoringContext,\n EventEmitterWithErrorHandling,\n} from \"@fluidframework/telemetry-utils\";\nimport type { Socket } from \"socket.io-client\";\n// For now, this package is versioned and released in unison with the specific drivers\nimport { pkgVersion as driverVersion } from \"./packageVersion\";\n\n/**\n * Represents a connection to a stream of delta updates\n */\nexport class DocumentDeltaConnection\n extends EventEmitterWithErrorHandling<IDocumentDeltaConnectionEvents>\n implements IDocumentDeltaConnection, IDisposable {\n static readonly eventsToForward = [\"nack\", \"op\", \"signal\", \"pong\"];\n\n // WARNING: These are critical events that we can't miss, so registration for them has to be in place at all times!\n // Including before handshake is over, and after that (but before DeltaManager had a chance to put its own handlers)\n static readonly eventsAlwaysForwarded = [\"disconnect\", \"error\"];\n\n /**\n * Last known sequence number to ordering service at the time of connection\n * It may lap actual last sequence number (quite a bit, if container is very active).\n * But it's best information for client to figure out how far it is behind, at least\n * for \"read\" connections. \"write\" connections may use own \"join\" op to similar information,\n * that is likely to be more up-to-date.\n */\n public checkpointSequenceNumber: number | undefined;\n\n // Listen for ops sent before we receive a response to connect_document\n protected readonly queuedMessages: ISequencedDocumentMessage[] = [];\n protected readonly queuedSignals: ISignalMessage[] = [];\n\n /**\n * A flag to indicate whether we have our handler attached. If it's attached, we're queueing incoming ops\n * to later be retrieved via initialMessages.\n */\n private earlyOpHandlerAttached: boolean = false;\n\n private socketConnectionTimeout: ReturnType<typeof setTimeout> | undefined;\n\n private _details: IConnected | undefined;\n\n // Listeners only needed while the connection is in progress\n private readonly connectionListeners: Map<string, (...args: any[]) => void> = new Map();\n // Listeners used throughout the lifetime of the DocumentDeltaConnection\n private readonly trackedListeners: Map<string, (...args: any[]) => void> = new Map();\n\n protected get hasDetails(): boolean {\n return !!this._details;\n }\n\n public get disposed() {\n assert(this._disposed || this.socket.connected, 0x244 /* \"Socket is closed, but connection is not!\" */);\n return this._disposed;\n }\n\n /**\n * Flag to indicate whether the DocumentDeltaConnection is expected to still be capable of sending messages.\n * After disconnection, we flip this to prevent any stale messages from being emitted.\n */\n protected _disposed: boolean = false;\n private readonly mc: MonitoringContext;\n\n /**\n * @deprecated Implementors should manage their own logger or monitoring context\n */\n protected get logger(): ITelemetryLogger {\n return this.mc.logger;\n }\n\n public get details(): IConnected {\n if (!this._details) {\n throw new Error(\"Internal error: calling method before _details is initialized!\");\n }\n return this._details;\n }\n\n /**\n * @param socket - websocket to be used\n * @param documentId - ID of the document\n * @param logger - for reporting telemetry events\n * @param enableLongPollingDowngrades - allow connection to be downgraded to long-polling on websocket failure\n */\n protected constructor(\n protected readonly socket: Socket,\n public documentId: string,\n logger: ITelemetryLogger,\n private readonly enableLongPollingDowngrades: boolean = false,\n ) {\n super((name, error) => {\n logger.sendErrorEvent(\n {\n eventName: \"DeltaConnection:EventException\",\n name,\n },\n error);\n });\n\n this.mc = loggerToMonitoringContext(\n ChildLogger.create(logger, \"DeltaConnection\"));\n\n this.on(\"newListener\", (event, listener) => {\n assert(!this.disposed, 0x20a /* \"register for event on disposed object\" */);\n\n // Some events are already forwarded - see this.addTrackedListener() calls in initialize().\n if (DocumentDeltaConnection.eventsAlwaysForwarded.includes(event)) {\n assert(this.trackedListeners.has(event), 0x245 /* \"tracked listener\" */);\n return;\n }\n\n if (!DocumentDeltaConnection.eventsToForward.includes(event)) {\n throw new Error(`DocumentDeltaConnection: Registering for unknown event: ${event}`);\n }\n\n // Whenever listener is added, we should subscribe on same event on socket, so these two things\n // should be in sync. This currently assumes that nobody unregisters and registers back listeners,\n // and that there are no \"internal\" listeners installed (like \"error\" case we skip above)\n // Better flow might be to always unconditionally register all handlers on successful connection,\n // though some logic (naming assert in initialMessages getter) might need to be adjusted (it becomes noop)\n assert((this.listeners(event).length !== 0) === this.trackedListeners.has(event), 0x20b /* \"mismatch\" */);\n if (!this.trackedListeners.has(event)) {\n this.addTrackedListener(\n event,\n (...args: any[]) => {\n this.emit(event, ...args);\n });\n }\n });\n }\n\n /**\n * Get the ID of the client who is sending the message\n *\n * @returns the client ID\n */\n public get clientId(): string {\n return this.details.clientId;\n }\n\n /**\n * Get the mode of the client\n *\n * @returns the client mode\n */\n public get mode(): ConnectionMode {\n return this.details.mode;\n }\n\n /**\n * Get the claims of the client who is sending the message\n *\n * @returns client claims\n */\n public get claims(): ITokenClaims {\n return this.details.claims;\n }\n\n /**\n * Get whether or not this is an existing document\n *\n * @returns true if the document exists\n */\n public get existing(): boolean {\n return this.details.existing;\n }\n\n /**\n * Get the maximum size of a message before chunking is required\n *\n * @returns the maximum size of a message before chunking is required\n */\n public get maxMessageSize(): number {\n return this.details.serviceConfiguration.maxMessageSize;\n }\n\n /**\n * Semver of protocol being used with the service\n */\n public get version(): string {\n return this.details.version;\n }\n\n /**\n * Configuration details provided by the service\n */\n public get serviceConfiguration(): IClientConfiguration {\n return this.details.serviceConfiguration;\n }\n\n private checkNotClosed() {\n assert(!this.disposed, 0x20c /* \"connection disposed\" */);\n }\n\n /**\n * Get messages sent during the connection\n *\n * @returns messages sent during the connection\n */\n public get initialMessages(): ISequencedDocumentMessage[] {\n this.checkNotClosed();\n\n // If we call this when the earlyOpHandler is not attached, then the queuedMessages may not include the\n // latest ops. This could possibly indicate that initialMessages was called twice.\n assert(this.earlyOpHandlerAttached, 0x08e /* \"Potentially missed initial messages\" */);\n // We will lose ops and perf will tank as we need to go to storage to become current!\n assert(this.listeners(\"op\").length !== 0, 0x08f /* \"No op handler is setup!\" */);\n\n this.removeEarlyOpHandler();\n\n if (this.queuedMessages.length > 0) {\n // Some messages were queued.\n // add them to the list of initialMessages to be processed\n this.details.initialMessages.push(...this.queuedMessages);\n this.details.initialMessages.sort((a, b) => a.sequenceNumber - b.sequenceNumber);\n this.queuedMessages.length = 0;\n }\n return this.details.initialMessages;\n }\n\n /**\n * Get signals sent during the connection\n *\n * @returns signals sent during the connection\n */\n public get initialSignals(): ISignalMessage[] {\n this.checkNotClosed();\n assert(this.listeners(\"signal\").length !== 0, 0x090 /* \"No signal handler is setup!\" */);\n\n this.removeEarlySignalHandler();\n\n if (this.queuedSignals.length > 0) {\n // Some signals were queued.\n // add them to the list of initialSignals to be processed\n this.details.initialSignals.push(...this.queuedSignals);\n this.queuedSignals.length = 0;\n }\n return this.details.initialSignals;\n }\n\n /**\n * Get initial client list\n *\n * @returns initial client list sent during the connection\n */\n public get initialClients(): ISignalClient[] {\n this.checkNotClosed();\n return this.details.initialClients;\n }\n\n protected emitMessages(type: string, messages: IDocumentMessage[][]) {\n // Although the implementation here disconnects the socket and does not reuse it, other subclasses\n // (e.g. OdspDocumentDeltaConnection) may reuse the socket. In these cases, we need to avoid emitting\n // on the still-live socket.\n if (!this.disposed) {\n this.socket.emit(type, this.clientId, messages);\n }\n }\n\n protected submitCore(type: string, messages: IDocumentMessage[]) {\n this.emitMessages(type, [messages]);\n }\n\n /**\n * Submits a new delta operation to the server\n *\n * @param message - delta operation to submit\n */\n public submit(messages: IDocumentMessage[]): void {\n this.checkNotClosed();\n this.submitCore(\"submitOp\", messages);\n }\n\n /**\n * Submits a new signal to the server\n *\n * @param message - signal to submit\n */\n public submitSignal(message: IDocumentMessage): void {\n this.checkNotClosed();\n this.submitCore(\"submitSignal\", [message]);\n }\n\n /**\n * Disconnect from the websocket, and permanently disable this DocumentDeltaConnection.\n */\n public dispose() {\n this.disposeCore(\n false, // socketProtocolError\n createGenericNetworkError(\n // pre-0.58 error message: clientClosingConnection\n \"Client closing delta connection\", { canRetry: true }, { driverVersion }));\n }\n\n protected disposeCore(socketProtocolError: boolean, err: IAnyDriverError) {\n // Can't check this.disposed here, as we get here on socket closure,\n // so _disposed & socket.connected might be not in sync while processing\n // \"dispose\" event.\n if (this._disposed) {\n return;\n }\n\n // We set the disposed flag as a part of the contract for overriding the disconnect method. This is used by\n // DocumentDeltaConnection to determine if emitting messages (ops) on the socket is allowed, which is\n // important since OdspDocumentDeltaConnection reuses the socket rather than truly disconnecting it. Note that\n // OdspDocumentDeltaConnection may still send disconnect_document which is allowed; this is only intended\n // to prevent normal messages from being emitted.\n this._disposed = true;\n\n this.removeTrackedListeners();\n this.disconnect(socketProtocolError, err);\n }\n\n /**\n * Disconnect from the websocket.\n * @param socketProtocolError - true if error happened on socket / socket.io protocol level\n * (not on Fluid protocol level)\n * @param reason - reason for disconnect\n */\n protected disconnect(socketProtocolError: boolean, reason: IAnyDriverError) {\n this.socket.disconnect();\n }\n\n protected async initialize(connectMessage: IConnect, timeout: number) {\n this.socket.on(\"op\", this.earlyOpHandler);\n this.socket.on(\"signal\", this.earlySignalHandler);\n this.earlyOpHandlerAttached = true;\n\n // Socket.io's reconnect_attempt event is unreliable, so we track connect_error count instead.\n let internalSocketConnectionFailureCount: number = 0;\n const isInternalSocketReconnectionEnabled = (): boolean => this.socket.io.reconnection();\n const getMaxInternalSocketReconnectionAttempts = (): number => isInternalSocketReconnectionEnabled()\n ? this.socket.io.reconnectionAttempts()\n : 0;\n const getMaxAllowedInternalSocketConnectionFailures = (): number =>\n getMaxInternalSocketReconnectionAttempts() + 1;\n\n this._details = await new Promise<IConnected>((resolve, reject) => {\n const fail = (socketProtocolError: boolean, err: IAnyDriverError) => {\n this.disposeCore(socketProtocolError, err);\n reject(err);\n };\n\n // Listen for connection issues\n this.addConnectionListener(\"connect_error\", (error) => {\n internalSocketConnectionFailureCount++;\n let isWebSocketTransportError = false;\n try {\n const description = error?.description;\n if (description && typeof description === \"object\") {\n if (error.type === \"TransportError\") {\n isWebSocketTransportError = true;\n }\n // That's a WebSocket. Clear it as we can't log it.\n description.target = undefined;\n }\n } catch (_e) { }\n\n // Handle socket transport downgrading when not offline.\n if (\n isWebSocketTransportError &&\n this.enableLongPollingDowngrades &&\n this.socket.io.opts.transports?.[0] !== \"polling\") {\n // Downgrade transports to polling upgrade mechanism.\n this.socket.io.opts.transports = [\"polling\", \"websocket\"];\n // Don't alter reconnection behavior if already enabled.\n if (!isInternalSocketReconnectionEnabled()) {\n // Allow single reconnection attempt using polling upgrade mechanism.\n this.socket.io.reconnection(true);\n this.socket.io.reconnectionAttempts(1);\n }\n }\n\n // Allow built-in socket.io reconnection handling.\n if (isInternalSocketReconnectionEnabled() &&\n internalSocketConnectionFailureCount < getMaxAllowedInternalSocketConnectionFailures()) {\n // Reconnection is enabled and maximum reconnect attempts have not been reached.\n return;\n }\n\n fail(true, this.createErrorObject(\"connect_error\", error));\n });\n\n // Listen for timeouts\n this.addConnectionListener(\"connect_timeout\", () => {\n fail(true, this.createErrorObject(\"connect_timeout\"));\n });\n\n this.addConnectionListener(\"connect_document_success\", (response: IConnected) => {\n // If we sent a nonce and the server supports nonces, check that the nonces match\n if (connectMessage.nonce !== undefined &&\n response.nonce !== undefined &&\n response.nonce !== connectMessage.nonce) {\n return;\n }\n\n const requestedMode = connectMessage.mode;\n const actualMode = response.mode;\n const writingPermitted = response.claims.scopes.includes(ScopeType.DocWrite);\n\n if (writingPermitted) {\n // The only time we expect a mismatch in requested/actual is if we lack write permissions\n // In this case we will get \"read\", even if we requested \"write\"\n if (actualMode !== requestedMode) {\n fail(false, this.createErrorObject(\n \"connect_document_success\",\n \"Connected in a different mode than was requested\",\n false,\n ));\n return;\n }\n } else {\n if (actualMode === \"write\") {\n fail(false, this.createErrorObject(\n \"connect_document_success\",\n \"Connected in write mode without write permissions\",\n false,\n ));\n return;\n }\n }\n\n this.checkpointSequenceNumber = response.checkpointSequenceNumber;\n\n this.removeConnectionListeners();\n resolve(response);\n });\n\n // Socket can be disconnected while waiting for Fluid protocol messages\n // (connect_document_error / connect_document_success), as well as before DeltaManager\n // had a chance to register its handlers.\n this.addTrackedListener(\"disconnect\", (reason) => {\n const err = this.createErrorObject(\"disconnect\", reason);\n this.emit(\"disconnect\", err);\n fail(true, err);\n });\n\n this.addTrackedListener(\"error\", ((error) => {\n // First, raise an error event, to give clients a chance to observe error contents\n // This includes \"Invalid namespace\" error, which we consider critical (reconnecting will not help)\n const err = this.createErrorObject(\"error\", error, error !== \"Invalid namespace\");\n this.emit(\"error\", err);\n // Disconnect socket - required if happened before initial handshake\n fail(true, err);\n }));\n\n this.addConnectionListener(\"connect_document_error\", ((error) => {\n // If we sent a nonce and the server supports nonces, check that the nonces match\n if (connectMessage.nonce !== undefined &&\n error.nonce !== undefined &&\n error.nonce !== connectMessage.nonce) {\n return;\n }\n\n // This is not an socket.io error - it's Fluid protocol error.\n // In this case fail connection and indicate that we were unable to create connection\n fail(false, this.createErrorObject(\"connect_document_error\", error));\n }));\n\n this.socket.emit(\"connect_document\", connectMessage);\n\n // Give extra 2 seconds for handshake on top of socket connection timeout\n this.socketConnectionTimeout = setTimeout(() => {\n fail(false, this.createErrorObject(\"orderingServiceHandshakeTimeout\"));\n }, timeout + 2000);\n });\n\n assert(!this.disposed, 0x246 /* \"checking consistency of socket & _disposed flags\" */);\n }\n\n protected earlyOpHandler = (documentId: string, msgs: ISequencedDocumentMessage[]) => {\n this.queuedMessages.push(...msgs);\n };\n\n protected earlySignalHandler = (msg: ISignalMessage) => {\n this.queuedSignals.push(msg);\n };\n\n private removeEarlyOpHandler() {\n this.socket.removeListener(\"op\", this.earlyOpHandler);\n this.earlyOpHandlerAttached = false;\n }\n\n private removeEarlySignalHandler() {\n this.socket.removeListener(\"signal\", this.earlySignalHandler);\n }\n\n private addConnectionListener(event: string, listener: (...args: any[]) => void) {\n assert(!DocumentDeltaConnection.eventsAlwaysForwarded.includes(event),\n 0x247 /* \"Use addTrackedListener instead\" */);\n assert(!DocumentDeltaConnection.eventsToForward.includes(event),\n 0x248 /* \"should not subscribe to forwarded events\" */);\n this.socket.on(event, listener);\n assert(!this.connectionListeners.has(event), 0x20d /* \"double connection listener\" */);\n this.connectionListeners.set(event, listener);\n }\n\n protected addTrackedListener(event: string, listener: (...args: any[]) => void) {\n this.socket.on(event, listener);\n assert(!this.trackedListeners.has(event), 0x20e /* \"double tracked listener\" */);\n this.trackedListeners.set(event, listener);\n }\n\n private removeTrackedListeners() {\n for (const [event, listener] of this.trackedListeners.entries()) {\n this.socket.off(event, listener);\n }\n // removeTrackedListeners removes all listeners, including connection listeners\n this.removeConnectionListeners();\n\n this.removeEarlyOpHandler();\n this.removeEarlySignalHandler();\n\n this.trackedListeners.clear();\n }\n\n private removeConnectionListeners() {\n if (this.socketConnectionTimeout !== undefined) {\n clearTimeout(this.socketConnectionTimeout);\n }\n\n for (const [event, listener] of this.connectionListeners.entries()) {\n this.socket.off(event, listener);\n }\n this.connectionListeners.clear();\n }\n\n /**\n * Error raising for socket.io issues\n */\n protected createErrorObject(handler: string, error?: any, canRetry = true): IAnyDriverError {\n // Note: we suspect the incoming error object is either:\n // - a string: log it in the message (if not a string, it may contain PII but will print as [object Object])\n // - an Error object thrown by socket.io engine. Be careful with not recording PII!\n let message: string;\n if (error?.type === \"TransportError\") {\n // JSON.stringify drops Error.message\n const messagePrefix = (error?.message !== undefined)\n ? `${error.message}: `\n : \"\";\n\n // Websocket errors reported by engine.io-client.\n // They are Error objects with description containing WS error and description = \"TransportError\"\n // Please see https://github.com/socketio/engine.io-client/blob/7245b80/lib/transport.ts#L44,\n message = `${messagePrefix}${JSON.stringify(error, getCircularReplacer())}`;\n } else {\n message = extractLogSafeErrorProperties(error, true).message;\n }\n\n const errorObj = createGenericNetworkError(\n `socket.io (${handler}): ${message}`,\n { canRetry },\n { driverVersion },\n );\n\n return errorObj;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"documentDeltaConnection.js","sourceRoot":"","sources":["../src/documentDeltaConnection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAMtD,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EAUH,SAAS,GACZ,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EACH,WAAW,EACX,6BAA6B,EAC7B,mBAAmB,EACnB,yBAAyB,EAEzB,6BAA6B,GAChC,MAAM,iCAAiC,CAAC;AAEzC,sFAAsF;AACtF,OAAO,EAAE,UAAU,IAAI,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAE/D;;GAEG;AACH,MAAM,OAAO,uBACT,SAAQ,6BAA6D;IAkErE;;;;;OAKG;IACH,YACuB,MAAc,EAC1B,UAAkB,EACzB,MAA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DAAiD;YACjD,iGAAiG;YACjG,6FAA6F;YAC7F,OAAO,GAAG,GAAG,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,mBAAmB,EAAE,CAAC,EAAE,CAAC;SAC/E;aAAM;YACH,OAAO,GAAG,6BAA6B,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC;SAChE;QAED,MAAM,QAAQ,GAAG,yBAAyB,CACtC,cAAc,OAAO,MAAM,OAAO,EAAE,EACpC,EAAE,QAAQ,EAAE,EACZ,EAAE,aAAa,EAAE,CACpB,CAAC;QAEF,OAAO,QAAQ,CAAC;IACpB,CAAC;;AAhjBe,uCAAe,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AAEnE,mHAAmH;AACnH,oHAAoH;AACpG,6CAAqB,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport {\n IAnyDriverError,\n IDocumentDeltaConnection,\n IDocumentDeltaConnectionEvents,\n} from \"@fluidframework/driver-definitions\";\nimport { createGenericNetworkError } from \"@fluidframework/driver-utils\";\nimport {\n ConnectionMode,\n IClientConfiguration,\n IConnect,\n IConnected,\n IDocumentMessage,\n ISequencedDocumentMessage,\n ISignalClient,\n ISignalMessage,\n ITokenClaims,\n ScopeType,\n} from \"@fluidframework/protocol-definitions\";\nimport { IDisposable, ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport {\n ChildLogger,\n extractLogSafeErrorProperties,\n getCircularReplacer,\n loggerToMonitoringContext,\n MonitoringContext,\n EventEmitterWithErrorHandling,\n} from \"@fluidframework/telemetry-utils\";\nimport type { Socket } from \"socket.io-client\";\n// For now, this package is versioned and released in unison with the specific drivers\nimport { pkgVersion as driverVersion } from \"./packageVersion\";\n\n/**\n * Represents a connection to a stream of delta updates\n */\nexport class DocumentDeltaConnection\n extends EventEmitterWithErrorHandling<IDocumentDeltaConnectionEvents>\n implements IDocumentDeltaConnection, IDisposable {\n static readonly eventsToForward = [\"nack\", \"op\", \"signal\", \"pong\"];\n\n // WARNING: These are critical events that we can't miss, so registration for them has to be in place at all times!\n // Including before handshake is over, and after that (but before DeltaManager had a chance to put its own handlers)\n static readonly eventsAlwaysForwarded = [\"disconnect\", \"error\"];\n\n /**\n * Last known sequence number to ordering service at the time of connection\n * It may lap actual last sequence number (quite a bit, if container is very active).\n * But it's best information for client to figure out how far it is behind, at least\n * for \"read\" connections. \"write\" connections may use own \"join\" op to similar information,\n * that is likely to be more up-to-date.\n */\n public checkpointSequenceNumber: number | undefined;\n\n // Listen for ops sent before we receive a response to connect_document\n protected readonly queuedMessages: ISequencedDocumentMessage[] = [];\n protected readonly queuedSignals: ISignalMessage[] = [];\n\n /**\n * A flag to indicate whether we have our handler attached. If it's attached, we're queueing incoming ops\n * to later be retrieved via initialMessages.\n */\n private earlyOpHandlerAttached: boolean = false;\n\n private socketConnectionTimeout: ReturnType<typeof setTimeout> | undefined;\n\n private _details: IConnected | undefined;\n\n // Listeners only needed while the connection is in progress\n private readonly connectionListeners: Map<string, (...args: any[]) => void> = new Map();\n // Listeners used throughout the lifetime of the DocumentDeltaConnection\n private readonly trackedListeners: Map<string, (...args: any[]) => void> = new Map();\n\n protected get hasDetails(): boolean {\n return !!this._details;\n }\n\n public get disposed() {\n assert(this._disposed || this.socket.connected, 0x244 /* \"Socket is closed, but connection is not!\" */);\n return this._disposed;\n }\n\n /**\n * Flag to indicate whether the DocumentDeltaConnection is expected to still be capable of sending messages.\n * After disconnection, we flip this to prevent any stale messages from being emitted.\n */\n protected _disposed: boolean = false;\n private readonly mc: MonitoringContext;\n\n /**\n * @deprecated Implementors should manage their own logger or monitoring context\n */\n protected get logger(): ITelemetryLogger {\n return this.mc.logger;\n }\n\n public get details(): IConnected {\n if (!this._details) {\n throw new Error(\"Internal error: calling method before _details is initialized!\");\n }\n return this._details;\n }\n\n /**\n * @param socket - websocket to be used\n * @param documentId - ID of the document\n * @param logger - for reporting telemetry events\n * @param enableLongPollingDowngrades - allow connection to be downgraded to long-polling on websocket failure\n */\n protected constructor(\n protected readonly socket: Socket,\n public documentId: string,\n logger: ITelemetryLogger,\n private readonly enableLongPollingDowngrades: boolean = false,\n ) {\n super((name, error) => {\n logger.sendErrorEvent(\n {\n eventName: \"DeltaConnection:EventException\",\n name,\n },\n error);\n });\n\n this.mc = loggerToMonitoringContext(\n ChildLogger.create(logger, \"DeltaConnection\"));\n\n this.on(\"newListener\", (event, listener) => {\n assert(!this.disposed, 0x20a /* \"register for event on disposed object\" */);\n\n // Some events are already forwarded - see this.addTrackedListener() calls in initialize().\n if (DocumentDeltaConnection.eventsAlwaysForwarded.includes(event)) {\n assert(this.trackedListeners.has(event), 0x245 /* \"tracked listener\" */);\n return;\n }\n\n if (!DocumentDeltaConnection.eventsToForward.includes(event)) {\n throw new Error(`DocumentDeltaConnection: Registering for unknown event: ${event}`);\n }\n\n // Whenever listener is added, we should subscribe on same event on socket, so these two things\n // should be in sync. This currently assumes that nobody unregisters and registers back listeners,\n // and that there are no \"internal\" listeners installed (like \"error\" case we skip above)\n // Better flow might be to always unconditionally register all handlers on successful connection,\n // though some logic (naming assert in initialMessages getter) might need to be adjusted (it becomes noop)\n assert((this.listeners(event).length !== 0) === this.trackedListeners.has(event), 0x20b /* \"mismatch\" */);\n if (!this.trackedListeners.has(event)) {\n this.addTrackedListener(\n event,\n (...args: any[]) => {\n this.emit(event, ...args);\n });\n }\n });\n }\n\n /**\n * Get the ID of the client who is sending the message\n *\n * @returns the client ID\n */\n public get clientId(): string {\n return this.details.clientId;\n }\n\n /**\n * Get the mode of the client\n *\n * @returns the client mode\n */\n public get mode(): ConnectionMode {\n return this.details.mode;\n }\n\n /**\n * Get the claims of the client who is sending the message\n *\n * @returns client claims\n */\n public get claims(): ITokenClaims {\n return this.details.claims;\n }\n\n /**\n * Get whether or not this is an existing document\n *\n * @returns true if the document exists\n */\n public get existing(): boolean {\n return this.details.existing;\n }\n\n /**\n * Get the maximum size of a message before chunking is required\n *\n * @returns the maximum size of a message before chunking is required\n */\n public get maxMessageSize(): number {\n return this.details.serviceConfiguration.maxMessageSize;\n }\n\n /**\n * Semver of protocol being used with the service\n */\n public get version(): string {\n return this.details.version;\n }\n\n /**\n * Configuration details provided by the service\n */\n public get serviceConfiguration(): IClientConfiguration {\n return this.details.serviceConfiguration;\n }\n\n private checkNotClosed() {\n assert(!this.disposed, 0x20c /* \"connection disposed\" */);\n }\n\n /**\n * Get messages sent during the connection\n *\n * @returns messages sent during the connection\n */\n public get initialMessages(): ISequencedDocumentMessage[] {\n this.checkNotClosed();\n\n // If we call this when the earlyOpHandler is not attached, then the queuedMessages may not include the\n // latest ops. This could possibly indicate that initialMessages was called twice.\n assert(this.earlyOpHandlerAttached, 0x08e /* \"Potentially missed initial messages\" */);\n // We will lose ops and perf will tank as we need to go to storage to become current!\n assert(this.listeners(\"op\").length !== 0, 0x08f /* \"No op handler is setup!\" */);\n\n this.removeEarlyOpHandler();\n\n if (this.queuedMessages.length > 0) {\n // Some messages were queued.\n // add them to the list of initialMessages to be processed\n this.details.initialMessages.push(...this.queuedMessages);\n this.details.initialMessages.sort((a, b) => a.sequenceNumber - b.sequenceNumber);\n this.queuedMessages.length = 0;\n }\n return this.details.initialMessages;\n }\n\n /**\n * Get signals sent during the connection\n *\n * @returns signals sent during the connection\n */\n public get initialSignals(): ISignalMessage[] {\n this.checkNotClosed();\n assert(this.listeners(\"signal\").length !== 0, 0x090 /* \"No signal handler is setup!\" */);\n\n this.removeEarlySignalHandler();\n\n if (this.queuedSignals.length > 0) {\n // Some signals were queued.\n // add them to the list of initialSignals to be processed\n this.details.initialSignals.push(...this.queuedSignals);\n this.queuedSignals.length = 0;\n }\n return this.details.initialSignals;\n }\n\n /**\n * Get initial client list\n *\n * @returns initial client list sent during the connection\n */\n public get initialClients(): ISignalClient[] {\n this.checkNotClosed();\n return this.details.initialClients;\n }\n\n protected emitMessages(type: string, messages: IDocumentMessage[][]) {\n // Although the implementation here disconnects the socket and does not reuse it, other subclasses\n // (e.g. OdspDocumentDeltaConnection) may reuse the socket. In these cases, we need to avoid emitting\n // on the still-live socket.\n if (!this.disposed) {\n this.socket.emit(type, this.clientId, messages);\n }\n }\n\n protected submitCore(type: string, messages: IDocumentMessage[]) {\n this.emitMessages(type, [messages]);\n }\n\n /**\n * Submits a new delta operation to the server\n *\n * @param message - delta operation to submit\n */\n public submit(messages: IDocumentMessage[]): void {\n this.checkNotClosed();\n this.submitCore(\"submitOp\", messages);\n }\n\n /**\n * Submits a new signal to the server\n *\n * @param message - signal to submit\n */\n public submitSignal(message: IDocumentMessage): void {\n this.checkNotClosed();\n this.submitCore(\"submitSignal\", [message]);\n }\n\n /**\n * Disconnect from the websocket and close the websocket too.\n */\n protected closeSocket(error: IAnyDriverError) {\n this.disconnect(error);\n }\n\n /**\n * Disconnect from the websocket, and permanently disable this DocumentDeltaConnection and close the socket.\n * However the OdspDocumentDeltaConnection differ in dispose as in there we don't close the socket. There is no\n * multiplexing here, so we need to close the socket here.\n */\n public dispose() {\n this.disconnect(createGenericNetworkError(\n // pre-0.58 error message: clientClosingConnection\n \"Client closing delta connection\", { canRetry: true }, { driverVersion }),\n );\n }\n\n protected disconnect(err: IAnyDriverError) {\n // Can't check this.disposed here, as we get here on socket closure,\n // so _disposed & socket.connected might be not in sync while processing\n // \"dispose\" event.\n if (this._disposed) {\n return;\n }\n\n // We set the disposed flag as a part of the contract for overriding the disconnect method. This is used by\n // DocumentDeltaConnection to determine if emitting messages (ops) on the socket is allowed, which is\n // important since OdspDocumentDeltaConnection reuses the socket rather than truly disconnecting it. Note that\n // OdspDocumentDeltaConnection may still send disconnect_document which is allowed; this is only intended\n // to prevent normal messages from being emitted.\n this._disposed = true;\n\n // Let user of connection object know about disconnect. This has to happen in betwee setting _disposed and\n // removing all listeners!\n this.emit(\"disconnect\", err);\n\n // user of DeltaConnection should have processed \"disconnect\" event and removed all listeners. Not clear\n // if we want to enforce that, as some users (like LocalDocumentService) do not unregister any handlers\n // assert(this.listenerCount(\"disconnect\") === 0, \"'disconnect` events should be processed synchronously\");\n\n this.removeTrackedListeners();\n this.disconnectCore();\n }\n\n /**\n * Disconnect from the websocket.\n * @param reason - reason for disconnect\n */\n protected disconnectCore() {\n this.socket.disconnect();\n }\n\n protected async initialize(connectMessage: IConnect, timeout: number) {\n this.socket.on(\"op\", this.earlyOpHandler);\n this.socket.on(\"signal\", this.earlySignalHandler);\n this.earlyOpHandlerAttached = true;\n\n // Socket.io's reconnect_attempt event is unreliable, so we track connect_error count instead.\n let internalSocketConnectionFailureCount: number = 0;\n const isInternalSocketReconnectionEnabled = (): boolean => this.socket.io.reconnection();\n const getMaxInternalSocketReconnectionAttempts = (): number => isInternalSocketReconnectionEnabled()\n ? this.socket.io.reconnectionAttempts()\n : 0;\n const getMaxAllowedInternalSocketConnectionFailures = (): number =>\n getMaxInternalSocketReconnectionAttempts() + 1;\n\n this._details = await new Promise<IConnected>((resolve, reject) => {\n const failAndCloseSocket = (err: IAnyDriverError) => {\n this.closeSocket(err);\n reject(err);\n };\n\n const failConnection = (err: IAnyDriverError) => {\n this.disconnect(err);\n reject(err);\n };\n // Listen for connection issues\n this.addConnectionListener(\"connect_error\", (error) => {\n internalSocketConnectionFailureCount++;\n let isWebSocketTransportError = false;\n try {\n const description = error?.description;\n if (description && typeof description === \"object\") {\n if (error.type === \"TransportError\") {\n isWebSocketTransportError = true;\n }\n // That's a WebSocket. Clear it as we can't log it.\n description.target = undefined;\n }\n } catch (_e) { }\n\n // Handle socket transport downgrading when not offline.\n if (\n isWebSocketTransportError &&\n this.enableLongPollingDowngrades &&\n this.socket.io.opts.transports?.[0] !== \"polling\") {\n // Downgrade transports to polling upgrade mechanism.\n this.socket.io.opts.transports = [\"polling\", \"websocket\"];\n // Don't alter reconnection behavior if already enabled.\n if (!isInternalSocketReconnectionEnabled()) {\n // Allow single reconnection attempt using polling upgrade mechanism.\n this.socket.io.reconnection(true);\n this.socket.io.reconnectionAttempts(1);\n }\n }\n\n // Allow built-in socket.io reconnection handling.\n if (isInternalSocketReconnectionEnabled() &&\n internalSocketConnectionFailureCount < getMaxAllowedInternalSocketConnectionFailures()) {\n // Reconnection is enabled and maximum reconnect attempts have not been reached.\n return;\n }\n\n failAndCloseSocket(this.createErrorObject(\"connect_error\", error));\n });\n\n // Listen for timeouts\n this.addConnectionListener(\"connect_timeout\", () => {\n failAndCloseSocket(this.createErrorObject(\"connect_timeout\"));\n });\n\n this.addConnectionListener(\"connect_document_success\", (response: IConnected) => {\n // If we sent a nonce and the server supports nonces, check that the nonces match\n if (connectMessage.nonce !== undefined &&\n response.nonce !== undefined &&\n response.nonce !== connectMessage.nonce) {\n return;\n }\n\n const requestedMode = connectMessage.mode;\n const actualMode = response.mode;\n const writingPermitted = response.claims.scopes.includes(ScopeType.DocWrite);\n\n if (writingPermitted) {\n // The only time we expect a mismatch in requested/actual is if we lack write permissions\n // In this case we will get \"read\", even if we requested \"write\"\n if (actualMode !== requestedMode) {\n failConnection(this.createErrorObject(\n \"connect_document_success\",\n \"Connected in a different mode than was requested\",\n false,\n ));\n return;\n }\n } else {\n if (actualMode === \"write\") {\n failConnection(this.createErrorObject(\n \"connect_document_success\",\n \"Connected in write mode without write permissions\",\n false,\n ));\n return;\n }\n }\n\n this.checkpointSequenceNumber = response.checkpointSequenceNumber;\n\n this.removeConnectionListeners();\n resolve(response);\n });\n\n // Socket can be disconnected while waiting for Fluid protocol messages\n // (connect_document_error / connect_document_success), as well as before DeltaManager\n // had a chance to register its handlers.\n this.addTrackedListener(\"disconnect\", (reason) => {\n const err = this.createErrorObject(\"disconnect\", reason);\n this.emit(\"disconnect\", err);\n failAndCloseSocket(err);\n });\n\n this.addTrackedListener(\"error\", ((error) => {\n // First, raise an error event, to give clients a chance to observe error contents\n // This includes \"Invalid namespace\" error, which we consider critical (reconnecting will not help)\n const err = this.createErrorObject(\"error\", error, error !== \"Invalid namespace\");\n this.emit(\"error\", err);\n // Disconnect socket - required if happened before initial handshake\n failAndCloseSocket(err);\n }));\n\n this.addConnectionListener(\"connect_document_error\", ((error) => {\n // If we sent a nonce and the server supports nonces, check that the nonces match\n if (connectMessage.nonce !== undefined &&\n error.nonce !== undefined &&\n error.nonce !== connectMessage.nonce) {\n return;\n }\n\n // This is not an socket.io error - it's Fluid protocol error.\n // In this case fail connection and indicate that we were unable to create connection\n failConnection(this.createErrorObject(\"connect_document_error\", error));\n }));\n\n this.socket.emit(\"connect_document\", connectMessage);\n\n // Give extra 2 seconds for handshake on top of socket connection timeout\n this.socketConnectionTimeout = setTimeout(() => {\n failConnection(this.createErrorObject(\"orderingServiceHandshakeTimeout\"));\n }, timeout + 2000);\n });\n\n assert(!this.disposed, 0x246 /* \"checking consistency of socket & _disposed flags\" */);\n }\n\n protected earlyOpHandler = (documentId: string, msgs: ISequencedDocumentMessage[]) => {\n this.queuedMessages.push(...msgs);\n };\n\n protected earlySignalHandler = (msg: ISignalMessage) => {\n this.queuedSignals.push(msg);\n };\n\n private removeEarlyOpHandler() {\n this.socket.removeListener(\"op\", this.earlyOpHandler);\n this.earlyOpHandlerAttached = false;\n }\n\n private removeEarlySignalHandler() {\n this.socket.removeListener(\"signal\", this.earlySignalHandler);\n }\n\n private addConnectionListener(event: string, listener: (...args: any[]) => void) {\n assert(!DocumentDeltaConnection.eventsAlwaysForwarded.includes(event),\n 0x247 /* \"Use addTrackedListener instead\" */);\n assert(!DocumentDeltaConnection.eventsToForward.includes(event),\n 0x248 /* \"should not subscribe to forwarded events\" */);\n this.socket.on(event, listener);\n assert(!this.connectionListeners.has(event), 0x20d /* \"double connection listener\" */);\n this.connectionListeners.set(event, listener);\n }\n\n protected addTrackedListener(event: string, listener: (...args: any[]) => void) {\n this.socket.on(event, listener);\n assert(!this.trackedListeners.has(event), 0x20e /* \"double tracked listener\" */);\n this.trackedListeners.set(event, listener);\n }\n\n private removeTrackedListeners() {\n for (const [event, listener] of this.trackedListeners.entries()) {\n this.socket.off(event, listener);\n }\n // removeTrackedListeners removes all listeners, including connection listeners\n this.removeConnectionListeners();\n\n this.removeEarlyOpHandler();\n this.removeEarlySignalHandler();\n\n this.trackedListeners.clear();\n }\n\n private removeConnectionListeners() {\n if (this.socketConnectionTimeout !== undefined) {\n clearTimeout(this.socketConnectionTimeout);\n }\n\n for (const [event, listener] of this.connectionListeners.entries()) {\n this.socket.off(event, listener);\n }\n this.connectionListeners.clear();\n }\n\n /**\n * Error raising for socket.io issues\n */\n protected createErrorObject(handler: string, error?: any, canRetry = true): IAnyDriverError {\n // Note: we suspect the incoming error object is either:\n // - a string: log it in the message (if not a string, it may contain PII but will print as [object Object])\n // - an Error object thrown by socket.io engine. Be careful with not recording PII!\n let message: string;\n if (error?.type === \"TransportError\") {\n // JSON.stringify drops Error.message\n const messagePrefix = (error?.message !== undefined)\n ? `${error.message}: `\n : \"\";\n\n // Websocket errors reported by engine.io-client.\n // They are Error objects with description containing WS error and description = \"TransportError\"\n // Please see https://github.com/socketio/engine.io-client/blob/7245b80/lib/transport.ts#L44,\n message = `${messagePrefix}${JSON.stringify(error, getCircularReplacer())}`;\n } else {\n message = extractLogSafeErrorProperties(error, true).message;\n }\n\n const errorObj = createGenericNetworkError(\n `socket.io (${handler}): ${message}`,\n { canRetry },\n { driverVersion },\n );\n\n return errorObj;\n }\n}\n"]}
|
package/lib/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/driver-base";
|
|
8
|
-
export declare const pkgVersion = "2.0.0-internal.
|
|
8
|
+
export declare const pkgVersion = "2.0.0-internal.2.0.1";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/lib/packageVersion.js
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export const pkgName = "@fluidframework/driver-base";
|
|
8
|
-
export const pkgVersion = "2.0.0-internal.
|
|
8
|
+
export const pkgVersion = "2.0.0-internal.2.0.1";
|
|
9
9
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,6BAA6B,CAAC;AACrD,MAAM,CAAC,MAAM,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/driver-base\";\nexport const pkgVersion = \"2.0.0-internal.
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,6BAA6B,CAAC;AACrD,MAAM,CAAC,MAAM,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/driver-base\";\nexport const pkgVersion = \"2.0.0-internal.2.0.1\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/driver-base",
|
|
3
|
-
"version": "2.0.0-internal.
|
|
3
|
+
"version": "2.0.0-internal.2.0.1",
|
|
4
4
|
"description": "Shared driver code for Fluid driver implementations",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -30,19 +30,20 @@
|
|
|
30
30
|
"lint:fix": "npm run eslint:fix",
|
|
31
31
|
"tsc": "tsc",
|
|
32
32
|
"tsfmt": "tsfmt --verify",
|
|
33
|
-
"tsfmt:fix": "tsfmt --replace"
|
|
33
|
+
"tsfmt:fix": "tsfmt --replace",
|
|
34
|
+
"typetests:gen": "fluid-type-validator -g -d ."
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
36
37
|
"@fluidframework/common-definitions": "^0.20.1",
|
|
37
38
|
"@fluidframework/common-utils": "^1.0.0",
|
|
38
|
-
"@fluidframework/driver-definitions": ">=2.0.0-internal.
|
|
39
|
-
"@fluidframework/driver-utils": ">=2.0.0-internal.
|
|
40
|
-
"@fluidframework/protocol-definitions": "^1.
|
|
41
|
-
"@fluidframework/telemetry-utils": ">=2.0.0-internal.
|
|
39
|
+
"@fluidframework/driver-definitions": ">=2.0.0-internal.2.0.1 <2.0.0-internal.3.0.0",
|
|
40
|
+
"@fluidframework/driver-utils": ">=2.0.0-internal.2.0.1 <2.0.0-internal.3.0.0",
|
|
41
|
+
"@fluidframework/protocol-definitions": "^1.1.0",
|
|
42
|
+
"@fluidframework/telemetry-utils": ">=2.0.0-internal.2.0.1 <2.0.0-internal.3.0.0"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
45
|
"@fluidframework/build-common": "^1.0.0",
|
|
45
|
-
"@fluidframework/driver-base-previous": "npm:@fluidframework/driver-base
|
|
46
|
+
"@fluidframework/driver-base-previous": "npm:@fluidframework/driver-base@2.0.0-internal.2.0.0",
|
|
46
47
|
"@fluidframework/eslint-config-fluid": "^1.0.0",
|
|
47
48
|
"@microsoft/api-extractor": "^7.22.2",
|
|
48
49
|
"@rushstack/eslint-config": "^2.5.1",
|
|
@@ -56,7 +57,7 @@
|
|
|
56
57
|
"typescript-formatter": "7.1.0"
|
|
57
58
|
},
|
|
58
59
|
"typeValidation": {
|
|
59
|
-
"version": "2.0.0",
|
|
60
|
+
"version": "2.0.0-internal.2.0.1",
|
|
60
61
|
"broken": {}
|
|
61
62
|
}
|
|
62
|
-
}
|
|
63
|
+
}
|
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
import { assert } from "@fluidframework/common-utils";
|
|
7
7
|
import {
|
|
8
|
+
IAnyDriverError,
|
|
8
9
|
IDocumentDeltaConnection,
|
|
9
10
|
IDocumentDeltaConnectionEvents,
|
|
10
11
|
} from "@fluidframework/driver-definitions";
|
|
11
|
-
import { createGenericNetworkError
|
|
12
|
+
import { createGenericNetworkError } from "@fluidframework/driver-utils";
|
|
12
13
|
import {
|
|
13
14
|
ConnectionMode,
|
|
14
15
|
IClientConfiguration,
|
|
@@ -310,17 +311,25 @@ export class DocumentDeltaConnection
|
|
|
310
311
|
}
|
|
311
312
|
|
|
312
313
|
/**
|
|
313
|
-
* Disconnect from the websocket
|
|
314
|
+
* Disconnect from the websocket and close the websocket too.
|
|
315
|
+
*/
|
|
316
|
+
protected closeSocket(error: IAnyDriverError) {
|
|
317
|
+
this.disconnect(error);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Disconnect from the websocket, and permanently disable this DocumentDeltaConnection and close the socket.
|
|
322
|
+
* However the OdspDocumentDeltaConnection differ in dispose as in there we don't close the socket. There is no
|
|
323
|
+
* multiplexing here, so we need to close the socket here.
|
|
314
324
|
*/
|
|
315
325
|
public dispose() {
|
|
316
|
-
this.
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
"Client closing delta connection", { canRetry: true }, { driverVersion }));
|
|
326
|
+
this.disconnect(createGenericNetworkError(
|
|
327
|
+
// pre-0.58 error message: clientClosingConnection
|
|
328
|
+
"Client closing delta connection", { canRetry: true }, { driverVersion }),
|
|
329
|
+
);
|
|
321
330
|
}
|
|
322
331
|
|
|
323
|
-
protected
|
|
332
|
+
protected disconnect(err: IAnyDriverError) {
|
|
324
333
|
// Can't check this.disposed here, as we get here on socket closure,
|
|
325
334
|
// so _disposed & socket.connected might be not in sync while processing
|
|
326
335
|
// "dispose" event.
|
|
@@ -335,17 +344,23 @@ export class DocumentDeltaConnection
|
|
|
335
344
|
// to prevent normal messages from being emitted.
|
|
336
345
|
this._disposed = true;
|
|
337
346
|
|
|
347
|
+
// Let user of connection object know about disconnect. This has to happen in betwee setting _disposed and
|
|
348
|
+
// removing all listeners!
|
|
349
|
+
this.emit("disconnect", err);
|
|
350
|
+
|
|
351
|
+
// user of DeltaConnection should have processed "disconnect" event and removed all listeners. Not clear
|
|
352
|
+
// if we want to enforce that, as some users (like LocalDocumentService) do not unregister any handlers
|
|
353
|
+
// assert(this.listenerCount("disconnect") === 0, "'disconnect` events should be processed synchronously");
|
|
354
|
+
|
|
338
355
|
this.removeTrackedListeners();
|
|
339
|
-
this.
|
|
356
|
+
this.disconnectCore();
|
|
340
357
|
}
|
|
341
358
|
|
|
342
359
|
/**
|
|
343
360
|
* Disconnect from the websocket.
|
|
344
|
-
* @param socketProtocolError - true if error happened on socket / socket.io protocol level
|
|
345
|
-
* (not on Fluid protocol level)
|
|
346
361
|
* @param reason - reason for disconnect
|
|
347
362
|
*/
|
|
348
|
-
protected
|
|
363
|
+
protected disconnectCore() {
|
|
349
364
|
this.socket.disconnect();
|
|
350
365
|
}
|
|
351
366
|
|
|
@@ -364,11 +379,15 @@ export class DocumentDeltaConnection
|
|
|
364
379
|
getMaxInternalSocketReconnectionAttempts() + 1;
|
|
365
380
|
|
|
366
381
|
this._details = await new Promise<IConnected>((resolve, reject) => {
|
|
367
|
-
const
|
|
368
|
-
this.
|
|
382
|
+
const failAndCloseSocket = (err: IAnyDriverError) => {
|
|
383
|
+
this.closeSocket(err);
|
|
369
384
|
reject(err);
|
|
370
385
|
};
|
|
371
386
|
|
|
387
|
+
const failConnection = (err: IAnyDriverError) => {
|
|
388
|
+
this.disconnect(err);
|
|
389
|
+
reject(err);
|
|
390
|
+
};
|
|
372
391
|
// Listen for connection issues
|
|
373
392
|
this.addConnectionListener("connect_error", (error) => {
|
|
374
393
|
internalSocketConnectionFailureCount++;
|
|
@@ -406,12 +425,12 @@ export class DocumentDeltaConnection
|
|
|
406
425
|
return;
|
|
407
426
|
}
|
|
408
427
|
|
|
409
|
-
|
|
428
|
+
failAndCloseSocket(this.createErrorObject("connect_error", error));
|
|
410
429
|
});
|
|
411
430
|
|
|
412
431
|
// Listen for timeouts
|
|
413
432
|
this.addConnectionListener("connect_timeout", () => {
|
|
414
|
-
|
|
433
|
+
failAndCloseSocket(this.createErrorObject("connect_timeout"));
|
|
415
434
|
});
|
|
416
435
|
|
|
417
436
|
this.addConnectionListener("connect_document_success", (response: IConnected) => {
|
|
@@ -430,7 +449,7 @@ export class DocumentDeltaConnection
|
|
|
430
449
|
// The only time we expect a mismatch in requested/actual is if we lack write permissions
|
|
431
450
|
// In this case we will get "read", even if we requested "write"
|
|
432
451
|
if (actualMode !== requestedMode) {
|
|
433
|
-
|
|
452
|
+
failConnection(this.createErrorObject(
|
|
434
453
|
"connect_document_success",
|
|
435
454
|
"Connected in a different mode than was requested",
|
|
436
455
|
false,
|
|
@@ -439,7 +458,7 @@ export class DocumentDeltaConnection
|
|
|
439
458
|
}
|
|
440
459
|
} else {
|
|
441
460
|
if (actualMode === "write") {
|
|
442
|
-
|
|
461
|
+
failConnection(this.createErrorObject(
|
|
443
462
|
"connect_document_success",
|
|
444
463
|
"Connected in write mode without write permissions",
|
|
445
464
|
false,
|
|
@@ -460,7 +479,7 @@ export class DocumentDeltaConnection
|
|
|
460
479
|
this.addTrackedListener("disconnect", (reason) => {
|
|
461
480
|
const err = this.createErrorObject("disconnect", reason);
|
|
462
481
|
this.emit("disconnect", err);
|
|
463
|
-
|
|
482
|
+
failAndCloseSocket(err);
|
|
464
483
|
});
|
|
465
484
|
|
|
466
485
|
this.addTrackedListener("error", ((error) => {
|
|
@@ -469,7 +488,7 @@ export class DocumentDeltaConnection
|
|
|
469
488
|
const err = this.createErrorObject("error", error, error !== "Invalid namespace");
|
|
470
489
|
this.emit("error", err);
|
|
471
490
|
// Disconnect socket - required if happened before initial handshake
|
|
472
|
-
|
|
491
|
+
failAndCloseSocket(err);
|
|
473
492
|
}));
|
|
474
493
|
|
|
475
494
|
this.addConnectionListener("connect_document_error", ((error) => {
|
|
@@ -482,14 +501,14 @@ export class DocumentDeltaConnection
|
|
|
482
501
|
|
|
483
502
|
// This is not an socket.io error - it's Fluid protocol error.
|
|
484
503
|
// In this case fail connection and indicate that we were unable to create connection
|
|
485
|
-
|
|
504
|
+
failConnection(this.createErrorObject("connect_document_error", error));
|
|
486
505
|
}));
|
|
487
506
|
|
|
488
507
|
this.socket.emit("connect_document", connectMessage);
|
|
489
508
|
|
|
490
509
|
// Give extra 2 seconds for handshake on top of socket connection timeout
|
|
491
510
|
this.socketConnectionTimeout = setTimeout(() => {
|
|
492
|
-
|
|
511
|
+
failConnection(this.createErrorObject("orderingServiceHandshakeTimeout"));
|
|
493
512
|
}, timeout + 2000);
|
|
494
513
|
});
|
|
495
514
|
|
package/src/packageVersion.ts
CHANGED