@fluidframework/container-loader 2.0.0-internal.1.2.0.93071 → 2.0.0-internal.1.2.2

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.
Files changed (58) hide show
  1. package/dist/catchUpMonitor.d.ts +6 -17
  2. package/dist/catchUpMonitor.d.ts.map +1 -1
  3. package/dist/catchUpMonitor.js +5 -36
  4. package/dist/catchUpMonitor.js.map +1 -1
  5. package/dist/connectionManager.d.ts.map +1 -1
  6. package/dist/connectionManager.js +3 -6
  7. package/dist/connectionManager.js.map +1 -1
  8. package/dist/connectionStateHandler.d.ts +80 -26
  9. package/dist/connectionStateHandler.d.ts.map +1 -1
  10. package/dist/connectionStateHandler.js +170 -89
  11. package/dist/connectionStateHandler.js.map +1 -1
  12. package/dist/container.d.ts +12 -11
  13. package/dist/container.d.ts.map +1 -1
  14. package/dist/container.js +76 -100
  15. package/dist/container.js.map +1 -1
  16. package/dist/containerStorageAdapter.d.ts +10 -24
  17. package/dist/containerStorageAdapter.d.ts.map +1 -1
  18. package/dist/containerStorageAdapter.js +50 -16
  19. package/dist/containerStorageAdapter.js.map +1 -1
  20. package/dist/deltaManager.js +4 -4
  21. package/dist/deltaManager.js.map +1 -1
  22. package/dist/packageVersion.d.ts +1 -1
  23. package/dist/packageVersion.d.ts.map +1 -1
  24. package/dist/packageVersion.js +1 -1
  25. package/dist/packageVersion.js.map +1 -1
  26. package/lib/catchUpMonitor.d.ts +6 -17
  27. package/lib/catchUpMonitor.d.ts.map +1 -1
  28. package/lib/catchUpMonitor.js +5 -35
  29. package/lib/catchUpMonitor.js.map +1 -1
  30. package/lib/connectionManager.d.ts.map +1 -1
  31. package/lib/connectionManager.js +3 -6
  32. package/lib/connectionManager.js.map +1 -1
  33. package/lib/connectionStateHandler.d.ts +80 -26
  34. package/lib/connectionStateHandler.d.ts.map +1 -1
  35. package/lib/connectionStateHandler.js +170 -90
  36. package/lib/connectionStateHandler.js.map +1 -1
  37. package/lib/container.d.ts +12 -11
  38. package/lib/container.d.ts.map +1 -1
  39. package/lib/container.js +77 -101
  40. package/lib/container.js.map +1 -1
  41. package/lib/containerStorageAdapter.d.ts +10 -24
  42. package/lib/containerStorageAdapter.d.ts.map +1 -1
  43. package/lib/containerStorageAdapter.js +50 -15
  44. package/lib/containerStorageAdapter.js.map +1 -1
  45. package/lib/deltaManager.js +4 -4
  46. package/lib/deltaManager.js.map +1 -1
  47. package/lib/packageVersion.d.ts +1 -1
  48. package/lib/packageVersion.d.ts.map +1 -1
  49. package/lib/packageVersion.js +1 -1
  50. package/lib/packageVersion.js.map +1 -1
  51. package/package.json +11 -11
  52. package/src/catchUpMonitor.ts +7 -47
  53. package/src/connectionManager.ts +3 -5
  54. package/src/connectionStateHandler.ts +231 -106
  55. package/src/container.ts +89 -118
  56. package/src/containerStorageAdapter.ts +64 -15
  57. package/src/deltaManager.ts +4 -4
  58. package/src/packageVersion.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"connectionStateHandler.js","sourceRoot":"","sources":["../src/connectionStateHandler.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,+DAA6D;AAI7D,qEAAmE;AACnE,uDAAoD;AACpD,qDAA4F;AAmB5F,MAAM,eAAe,GAAG,KAAK,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAa,sBAAsB;IAyB/B,YACqB,OAAsC,EACtC,MAAwB,EACjC,SAAkB;;QAFT,YAAO,GAAP,OAAO,CAA+B;QACtC,WAAM,GAAN,MAAM,CAAkB;QACjC,cAAS,GAAT,SAAS,CAAS;QA3BtB,qBAAgB,GAAG,iCAAe,CAAC,YAAY,CAAC;QAoKvC,+BAA0B,GAAG,GAAG,EAAE;YAC/C,kFAAkF;YAClF,IAAI,IAAI,CAAC,gBAAgB,KAAK,iCAAe,CAAC,UAAU,EAAE;gBACtD,IAAI,CAAC,kBAAkB,CAAC,iCAAe,CAAC,SAAS,CAAC,CAAC;aACtD;iBAAM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AC,QAAQ,EAAE,EAAE;YAC5C,IAAI,CAAC,yBAAyB,CAAC,QAAQ,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;QAEH,wFAAwF;QACxF,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,IAAI,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,SAAS,EAAE;YACvF,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,CAAC;SACtC;IACL,CAAC;CACJ;AAvUD,wDAuUC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger, ITelemetryProperties } from \"@fluidframework/common-definitions\";\nimport { assert, Timer } from \"@fluidframework/common-utils\";\nimport { IConnectionDetails, IDeltaManager } from \"@fluidframework/container-definitions\";\nimport { ILocalSequencedClient, IProtocolHandler } from \"@fluidframework/protocol-base\";\nimport { ConnectionMode, IQuorumClients } from \"@fluidframework/protocol-definitions\";\nimport { PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport { ConnectionState } from \"./connectionState\";\nimport { CatchUpMonitor, ICatchUpMonitor, ImmediateCatchUpMonitor } from \"./catchUpMonitor\";\n\n/** Constructor parameter type for passing in dependencies needed by the ConnectionStateHandler */\nexport interface IConnectionStateHandlerInputs {\n /** Provides access to the clients currently in the quorum */\n quorumClients: () => IQuorumClients | undefined;\n /** Log to telemetry any change in state, included to Connecting */\n logConnectionStateChangeTelemetry:\n (value: ConnectionState, oldState: ConnectionState, reason?: string | undefined) => void;\n /** Whether to expect the client to join in write mode on next connection */\n shouldClientJoinWrite: () => boolean;\n /** (Optional) How long should we wait on our previous client's Leave op before transitioning to Connected again */\n maxClientLeaveWaitTime: number | undefined;\n /** Log an issue encountered while in the Connecting state. details will be logged as a JSON string */\n logConnectionIssue: (eventName: string, details?: ITelemetryProperties) => void;\n /** Callback whenever the ConnectionState changes between Disconnected and Connected */\n connectionStateChanged: () => void;\n}\n\nconst JoinOpTimeoutMs = 45000;\n\n/**\n * In the lifetime of a container, the connection will likely disconnect and reconnect periodically.\n * This class ensures that any ops sent by this container instance on previous connection are either\n * sequenced or blocked by the server before emitting the new \"connected\" event and allowing runtime to resubmit ops.\n *\n * Each connection is assigned a clientId by the service, and the connection is book-ended by a Join and a Leave op\n * generated by the service. Due to the distributed nature of the Relay Service, in the case of reconnect we cannot\n * make any assumptions about ordering of operations between the old and new connections - i.e. new Join op could\n * be sequenced before old Leave op (and some acks from pending ops that were in flight when we disconnected).\n *\n * The job of this class is to encapsulate the transition period during reconnect, which is identified by\n * ConnectionState.CatchingUp. Specifically, before moving to Connected state with the new clientId, it ensures that:\n * (A) We process the Leave op for the previous clientId. This allows us to properly handle any acks from in-flight ops\n * that got sequenced with the old clientId (we'll recognize them as local ops). After the Leave op, any other\n * pending ops can safely be submitted with the new clientId without fear of duplication in the sequenced op stream.\n * (B) We process the Join op for the new clientId (identified when the underlying connection was first established),\n * indicating the service is ready to sequence ops sent with the new clientId.\n * (C) We process all ops known at the time the underlying connection was established (so we are \"caught up\")\n *\n * For (A) we give up waiting after some time (same timeout as server uses), and go ahead and transition to Connected.\n * For (B) we log telemetry if it takes too long, but still only transition to Connected when the Join op is processed\n * and we are added to the Quorum.\n * For (C) this is optional behavior, controlled by the parameters of receivedConnectEvent\n */\nexport class ConnectionStateHandler {\n private _connectionState = ConnectionState.Disconnected;\n private _pendingClientId: string | undefined;\n private catchUpMonitor: ICatchUpMonitor | undefined;\n private readonly prevClientLeftTimer: Timer;\n private readonly joinOpTimer: Timer;\n\n private waitEvent: PerformanceEvent | undefined;\n\n public get connectionState(): ConnectionState {\n return this._connectionState;\n }\n\n public get connected(): boolean {\n return this.connectionState === ConnectionState.Connected;\n }\n\n public get clientId(): string | undefined {\n return this._clientId;\n }\n\n public get pendingClientId(): string | undefined {\n return this._pendingClientId;\n }\n\n constructor(\n private readonly handler: IConnectionStateHandlerInputs,\n private readonly logger: ITelemetryLogger,\n private _clientId?: string,\n ) {\n this.prevClientLeftTimer = new Timer(\n // Default is 5 min for which we are going to wait for its own \"leave\" message. This is same as\n // the max time on server after which leave op is sent.\n this.handler.maxClientLeaveWaitTime ?? 300000,\n () => {\n assert(!this.connected,\n 0x2ac /* \"Connected when timeout waiting for leave from previous session fired!\" */);\n this.applyForConnectedState(\"timeout\");\n },\n );\n\n // Based on recent data, it looks like majority of cases where we get stuck are due to really slow or\n // timing out ops fetches. So attempt recovery infrequently. Also fetch uses 30 second timeout, so\n // if retrying fixes the problem, we should not see these events.\n this.joinOpTimer = new Timer(\n JoinOpTimeoutMs,\n () => {\n // I've observed timer firing within couple ms from disconnect event, looks like\n // queued timer callback is not cancelled if timer is cancelled while callback sits in the queue.\n if (this.connectionState !== ConnectionState.CatchingUp) {\n return;\n }\n const quorumClients = this.handler.quorumClients();\n const details = {\n quorumInitialized: quorumClients !== undefined,\n pendingClientId: this.pendingClientId,\n inQuorum: quorumClients?.getMember(this.pendingClientId ?? \"\") !== undefined,\n waitingForLeaveOp: this.waitingForLeaveOp,\n };\n this.handler.logConnectionIssue(\"NoJoinOp\", details);\n },\n );\n }\n\n private startJoinOpTimer() {\n assert(!this.joinOpTimer.hasTimer, 0x234 /* \"has joinOpTimer\" */);\n this.joinOpTimer.start();\n }\n\n private stopJoinOpTimer() {\n assert(this.joinOpTimer.hasTimer, 0x235 /* \"no joinOpTimer\" */);\n this.joinOpTimer.clear();\n }\n\n private get waitingForLeaveOp() {\n return this.prevClientLeftTimer.hasTimer;\n }\n\n public dispose() {\n assert(!this.joinOpTimer.hasTimer, 0x2a5 /* \"join timer\" */);\n this.prevClientLeftTimer.clear();\n }\n\n public containerSaved() {\n // If we were waiting for moving to Connected state, then only apply for state change. Since the container\n // is now saved and we don't have any ops to roundtrip, we can clear the timer and apply for connected state.\n if (this.waitingForLeaveOp) {\n this.prevClientLeftTimer.clear();\n this.applyForConnectedState(\"containerSaved\");\n }\n }\n\n private receivedAddMemberEvent(clientId: string) {\n // This is the only one that requires the pending client ID\n if (clientId === this.pendingClientId) {\n if (this.joinOpTimer.hasTimer) {\n this.stopJoinOpTimer();\n } else {\n // timer has already fired, meaning it took too long to get join on.\n // Record how long it actually took to recover.\n this.handler.logConnectionIssue(\"ReceivedJoinOp\");\n }\n // Start the event in case we are waiting for leave or timeout.\n if (this.waitingForLeaveOp) {\n this.waitEvent = PerformanceEvent.start(this.logger, {\n eventName: \"WaitBeforeClientLeave\",\n details: JSON.stringify({\n waitOnClientId: this._clientId,\n hadOutstandingOps: this.handler.shouldClientJoinWrite(),\n }),\n });\n }\n this.applyForConnectedState(\"addMemberEvent\");\n }\n }\n\n private applyForConnectedState(source: \"removeMemberEvent\" | \"addMemberEvent\" | \"timeout\" | \"containerSaved\") {\n const quorumClients = this.handler.quorumClients();\n assert(quorumClients !== undefined, 0x236 /* \"In all cases it should be already installed\" */);\n\n assert(this.waitingForLeaveOp === false ||\n (this.clientId !== undefined && quorumClients.getMember(this.clientId) !== undefined),\n 0x2e2 /* \"Must only wait for leave message when clientId in quorum\" */);\n\n // Move to connected state only if we are in Connecting state, we have seen our join op\n // and there is no timer running which means we are not waiting for previous client to leave\n // or timeout has occurred while doing so.\n if (this.pendingClientId !== this.clientId\n && this.pendingClientId !== undefined\n && quorumClients.getMember(this.pendingClientId) !== undefined\n && !this.waitingForLeaveOp\n ) {\n this.waitEvent?.end({ source });\n\n assert(this.catchUpMonitor !== undefined,\n 0x37d /* catchUpMonitor should always be set if pendingClientId is set */);\n this.catchUpMonitor.on(\"caughtUp\", this.transitionToConnectedState);\n } else {\n // Adding this event temporarily so that we can get help debugging if something goes wrong.\n this.logger.sendTelemetryEvent({\n eventName: \"connectedStateRejected\",\n category: source === \"timeout\" ? \"error\" : \"generic\",\n details: JSON.stringify({\n source,\n pendingClientId: this.pendingClientId,\n clientId: this.clientId,\n waitingForLeaveOp: this.waitingForLeaveOp,\n inQuorum: quorumClients?.getMember(this.pendingClientId ?? \"\") !== undefined,\n }),\n });\n }\n }\n\n private receivedRemoveMemberEvent(clientId: string) {\n // If the client which has left was us, then finish the timer.\n if (this.clientId === clientId) {\n this.prevClientLeftTimer.clear();\n this.applyForConnectedState(\"removeMemberEvent\");\n }\n }\n\n public receivedDisconnectEvent(reason: string) {\n this.setConnectionState(ConnectionState.Disconnected, reason);\n }\n\n private readonly transitionToConnectedState = () => {\n // Defensive measure, we should always be in CatchingUp state when this is called.\n if (this._connectionState === ConnectionState.CatchingUp) {\n this.setConnectionState(ConnectionState.Connected);\n } else {\n this.logger.sendTelemetryEvent({\n eventName: \"cannotTransitionToConnectedState\",\n connectionState: ConnectionState[this._connectionState],\n });\n }\n };\n\n /**\n * The \"connect\" event indicates the connection to the Relay Service is live.\n * However, some additional conditions must be met before we can fully transition to\n * \"Connected\" state. This function handles that interim period, known as \"Connecting\" state.\n * @param connectionMode - Read or Write connection\n * @param details - Connection details returned from the Relay Service\n * @param deltaManager - DeltaManager to be used for delaying Connected transition until caught up.\n * If it's undefined, then don't delay and transition to Connected as soon as Leave/Join op are accounted for\n */\n public receivedConnectEvent(\n connectionMode: ConnectionMode,\n details: IConnectionDetails,\n deltaManager?: IDeltaManager<any, any>,\n ) {\n const oldState = this._connectionState;\n this._connectionState = ConnectionState.CatchingUp;\n\n const writeConnection = connectionMode === \"write\";\n assert(!this.handler.shouldClientJoinWrite() || writeConnection,\n 0x30a /* shouldClientJoinWrite should imply this is a writeConnection */);\n assert(!this.waitingForLeaveOp || writeConnection,\n 0x2a6 /* \"waitingForLeaveOp should imply writeConnection (we need to be ready to flush pending ops)\" */);\n\n // Defensive measure in case catchUpMonitor from previous connection attempt wasn't already cleared\n this.catchUpMonitor?.dispose();\n\n // Note that this may be undefined since the connection is established proactively on load\n // and the quorum may still be under initialization.\n const quorumClients: IQuorumClients | undefined = this.handler.quorumClients();\n\n // Stash the clientID to detect when transitioning from connecting (socket.io channel open) to connected\n // (have received the join message for the client ID)\n // This is especially important in the reconnect case. It's possible there could be outstanding\n // ops sent by this client, so we should keep the old client id until we see our own client's\n // join message. after we see the join message for our new connection with our new client id,\n // we know there can no longer be outstanding ops that we sent with the previous client id.\n this._pendingClientId = details.clientId;\n\n // We may want to catch up to known ops as of now before transitioning to Connected state\n this.catchUpMonitor = deltaManager !== undefined\n ? new CatchUpMonitor(deltaManager)\n : new ImmediateCatchUpMonitor();\n\n // IMPORTANT: Report telemetry after we set _pendingClientId, but before transitioning to Connected state\n this.handler.logConnectionStateChangeTelemetry(ConnectionState.CatchingUp, oldState);\n\n // For write connections, this pending clientId could be in the quorum already (i.e. join op already processed).\n // We are fetching ops from storage in parallel to connecting to Relay Service,\n // and given async processes, it's possible that we have already processed our own join message before\n // connection was fully established.\n // If quorumClients itself is undefined, we expect it will process the join op after it's initialized.\n const waitingForJoinOp = writeConnection && quorumClients?.getMember(this._pendingClientId) === undefined;\n\n if (waitingForJoinOp) {\n // Previous client left, and we are waiting for our own join op. When it is processed we'll join the quorum\n // and attempt to transition to Connected state via receivedAddMemberEvent.\n this.startJoinOpTimer();\n } else if (!this.waitingForLeaveOp) {\n // We're not waiting for Join or Leave op (if read-only connection those don't even apply),\n // but we do need to wait until we are caught up (to now-known ops) before transitioning to Connected state.\n this.catchUpMonitor.on(\"caughtUp\", this.transitionToConnectedState);\n }\n // else - We are waiting for Leave op still, do nothing for now, we will transition to Connected later\n }\n\n /** Clear all the state used during the Connecting phase (set in receivedConnectEvent) */\n private clearPendingConnectionState() {\n this._pendingClientId = undefined;\n\n this.catchUpMonitor?.dispose();\n this.catchUpMonitor = undefined;\n\n if (this.joinOpTimer.hasTimer) {\n this.stopJoinOpTimer();\n }\n }\n\n private setConnectionState(value: ConnectionState.Disconnected, reason: string): void;\n private setConnectionState(value: ConnectionState.Connected): void;\n private setConnectionState(value: ConnectionState, reason?: string): void {\n if (this.connectionState === value) {\n // Already in the desired state - exit early\n this.logger.sendErrorEvent({ eventName: \"setConnectionStateSame\", value });\n return;\n }\n\n const oldState = this._connectionState;\n this._connectionState = value;\n const quorumClients = this.handler.quorumClients();\n let client: ILocalSequencedClient | undefined;\n if (this._clientId !== undefined) {\n client = quorumClients?.getMember(this._clientId);\n }\n if (value === ConnectionState.Connected) {\n assert(oldState === ConnectionState.CatchingUp,\n 0x1d8 /* \"Should only transition from Connecting state\" */);\n // Mark our old client should have left in the quorum if it's still there\n if (client !== undefined) {\n client.shouldHaveLeft = true;\n }\n this._clientId = this.pendingClientId;\n } else if (value === ConnectionState.Disconnected) {\n // Clear pending state immediately to prepare for reconnect\n this.clearPendingConnectionState();\n\n // Only wait for \"leave\" message if the connected client exists in the quorum because only the write\n // client will exist in the quorum and only for those clients we will receive \"removeMember\" event and\n // the client has some unacked ops.\n // Also server would not accept ops from read client. Also check if the timer is not already running as\n // we could receive \"Disconnected\" event multiple times without getting connected and in that case we\n // don't want to reset the timer as we still want to wait on original client which started this timer.\n if (client !== undefined\n && this.handler.shouldClientJoinWrite()\n && this.prevClientLeftTimer.hasTimer === false\n ) {\n this.prevClientLeftTimer.restart();\n } else {\n // Adding this event temporarily so that we can get help debugging if something goes wrong.\n this.logger.sendTelemetryEvent({\n eventName: \"noWaitOnDisconnected\",\n details: JSON.stringify({\n inQuorum: client !== undefined,\n waitingForLeaveOp: this.waitingForLeaveOp,\n hadOutstandingOps: this.handler.shouldClientJoinWrite(),\n }),\n });\n }\n }\n\n // Report transition before we propagate event across layers\n this.handler.logConnectionStateChangeTelemetry(this._connectionState, oldState, reason);\n\n // Propagate event across layers\n this.handler.connectionStateChanged();\n }\n\n public initProtocol(protocol: IProtocolHandler) {\n protocol.quorum.on(\"addMember\", (clientId, _details) => {\n this.receivedAddMemberEvent(clientId);\n });\n\n protocol.quorum.on(\"removeMember\", (clientId) => {\n this.receivedRemoveMemberEvent(clientId);\n });\n\n // if we have a clientId from a previous container we need to wait for its leave message\n if (this.clientId !== undefined && protocol.quorum.getMember(this.clientId) !== undefined) {\n this.prevClientLeftTimer.restart();\n }\n }\n}\n"]}
1
+ {"version":3,"file":"connectionStateHandler.js","sourceRo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Q,EAAE,MAAM,CAAC,CAAC;IACjF,CAAC;IAED,uDAAuD;IACvD,2DAA2D;IAC3D,8DAA8D;IAC9D,IAAc,UAAU;;QACpB,OAAO,MAAA,IAAI,CAAC,QAAQ,0CAAE,MAAM,CAAC;IACjC,CAAC;IAEM,YAAY,CAAC,QAA0B;;QAC1C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,MAAA,IAAI,CAAC,UAAU,0CAAE,EAAE,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE,EAAE;YAC1C,IAAI,CAAC,sBAAsB,CAAC,QAAQ,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;QAEH,MAAA,IAAI,CAAC,UAAU,0CAAE,EAAE,CAAC,cAAc,EAAE,CAAC,QAAQ,EAAE,EAAE;YAC7C,IAAI,CAAC,yBAAyB,CAAC,QAAQ,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;QAEH,6FAA6F;QAC7F,mDAAmD;QACnD,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE;YACtC,oEAAoE;YACpE,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,eAAgB,CAAC,CAAC;SACtD;QAED,wFAAwF;QACxF,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;YAC9D,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,CAAC;SACtC;IACL,CAAC;IAES,SAAS,CAAC,QAAiB;;QACjC,OAAO,CAAA,MAAA,IAAI,CAAC,UAAU,0CAAE,SAAS,CAAC,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,EAAE,CAAC,MAAK,SAAS,CAAC;IACpE,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger, ITelemetryProperties } from \"@fluidframework/common-definitions\";\nimport { assert, Timer } from \"@fluidframework/common-utils\";\nimport { IConnectionDetails, IDeltaManager } from \"@fluidframework/container-definitions\";\nimport { ILocalSequencedClient } from \"@fluidframework/protocol-base\";\nimport { ConnectionMode } from \"@fluidframework/protocol-definitions\";\nimport { PerformanceEvent, loggerToMonitoringContext } from \"@fluidframework/telemetry-utils\";\nimport { ConnectionState } from \"./connectionState\";\nimport { CatchUpMonitor, ICatchUpMonitor } from \"./catchUpMonitor\";\nimport { IProtocolHandler } from \"./protocol\";\n\nconst JoinOpTimeoutMs = 45000;\n\n/** Constructor parameter type for passing in dependencies needed by the ConnectionStateHandler */\nexport interface IConnectionStateHandlerInputs {\n logger: ITelemetryLogger;\n /** Log to telemetry any change in state, included to Connecting */\n connectionStateChanged:\n (value: ConnectionState, oldState: ConnectionState, reason?: string | undefined) => void;\n /** Whether to expect the client to join in write mode on next connection */\n shouldClientJoinWrite: () => boolean;\n /** (Optional) How long should we wait on our previous client's Leave op before transitioning to Connected again */\n maxClientLeaveWaitTime: number | undefined;\n /** Log an issue encountered while in the Connecting state. details will be logged as a JSON string */\n logConnectionIssue: (eventName: string, details?: ITelemetryProperties) => void;\n}\n\n/**\n * interface that connection state handler implements\n */\nexport interface IConnectionStateHandler {\n readonly connectionState: ConnectionState;\n readonly pendingClientId: string | undefined;\n\n containerSaved(): void;\n dispose(): void;\n initProtocol(protocol: IProtocolHandler): void;\n receivedConnectEvent(connectionMode: ConnectionMode, details: IConnectionDetails): void;\n receivedDisconnectEvent(reason: string): void;\n}\n\nexport function createConnectionStateHandler(\n inputs: IConnectionStateHandlerInputs,\n deltaManager: IDeltaManager<any, any>,\n clientId?: string,\n) {\n const mc = loggerToMonitoringContext(inputs.logger);\n return createConnectionStateHandlerCore(\n mc.config.getBoolean(\"Fluid.Container.CatchUpBeforeDeclaringConnected\") === true,\n inputs,\n deltaManager,\n clientId,\n );\n}\n\nexport function createConnectionStateHandlerCore(\n wait: boolean,\n inputs: IConnectionStateHandlerInputs,\n deltaManager: IDeltaManager<any, any>,\n clientId?: string,\n) {\n if (!wait) {\n return new ConnectionStateHandler(inputs, clientId);\n }\n return new ConnectionStateCatchup(\n inputs,\n (handler: IConnectionStateHandlerInputs) => new ConnectionStateHandler(handler, clientId),\n deltaManager);\n}\n\n/**\n * Class that can be used as a base class for building IConnectionStateHandler adapters / pipeline.\n * It implements both ends of communication interfaces and passes data back and forward\n */\nclass ConnectionStateHandlerPassThrough implements IConnectionStateHandler, IConnectionStateHandlerInputs {\n protected readonly pimpl: IConnectionStateHandler;\n\n constructor(\n protected readonly inputs: IConnectionStateHandlerInputs,\n pimplFactory: (handler: IConnectionStateHandlerInputs) => IConnectionStateHandler,\n ) {\n this.pimpl = pimplFactory(this);\n }\n\n /**\n * IConnectionStateHandler\n */\n public get connectionState() { return this.pimpl.connectionState; }\n public get pendingClientId() { return this.pimpl.pendingClientId; }\n\n public containerSaved() { return this.pimpl.containerSaved(); }\n public dispose() { return this.pimpl.dispose(); }\n public initProtocol(protocol: IProtocolHandler) { return this.pimpl.initProtocol(protocol); }\n public receivedDisconnectEvent(reason: string) { return this.pimpl.receivedDisconnectEvent(reason); }\n\n public receivedConnectEvent(connectionMode: ConnectionMode, details: IConnectionDetails) {\n return this.pimpl.receivedConnectEvent(connectionMode, details);\n }\n\n /**\n * IConnectionStateHandlerInputs\n */\n\n public get logger() { return this.inputs.logger; }\n public connectionStateChanged(\n value: ConnectionState,\n oldState: ConnectionState,\n reason?: string | undefined,\n ) {\n return this.inputs.connectionStateChanged(value, oldState, reason);\n }\n public shouldClientJoinWrite() { return this.inputs.shouldClientJoinWrite(); }\n public get maxClientLeaveWaitTime() { return this.inputs.maxClientLeaveWaitTime; }\n public logConnectionIssue(eventName: string, details?: ITelemetryProperties) {\n return this.inputs.logConnectionIssue(eventName, details);\n }\n}\n\n/**\n * Implementation of IConnectionStateHandler pass-through adapter that waits for specific sequence number\n * before raising connected event\n */\nclass ConnectionStateCatchup extends ConnectionStateHandlerPassThrough {\n private catchUpMonitor: ICatchUpMonitor | undefined;\n\n constructor(\n inputs: IConnectionStateHandlerInputs,\n pimplFactory: (handler: IConnectionStateHandlerInputs) => IConnectionStateHandler,\n private readonly deltaManager: IDeltaManager<any, any>,\n ) {\n super(inputs, pimplFactory);\n this._connectionState = this.pimpl.connectionState;\n }\n\n private _connectionState: ConnectionState;\n public get connectionState() {\n return this._connectionState;\n }\n\n public connectionStateChanged(value: ConnectionState, oldState: ConnectionState, reason?: string | undefined) {\n switch (value) {\n case ConnectionState.Connected:\n assert(this._connectionState === ConnectionState.CatchingUp, 0x3e1 /* connectivity transitions */);\n // Create catch-up monitor here (not earlier), as we might get more exact info by now about how far\n // client is behind through join signal. This is only true if base layer uses signals (i.e. audience,\n // not quorum, including for \"rea\" connections) to make decisions about moving to \"connected\" state.\n // In addition to that, in its current form, doing this in ConnectionState.CatchingUp is dangerous as\n // we might get callback right away, and it will screw up state transition (as code outside of switch\n // statement will overwrite current state).\n assert(this.catchUpMonitor === undefined, 0x3eb /* catchUpMonitor should be gone */);\n this.catchUpMonitor = new CatchUpMonitor(this.deltaManager, this.transitionToConnectedState);\n return;\n case ConnectionState.Disconnected:\n this.catchUpMonitor?.dispose();\n this.catchUpMonitor = undefined;\n break;\n case ConnectionState.CatchingUp:\n assert(this._connectionState === ConnectionState.Disconnected, 0x3e3 /* connectivity transitions */);\n break;\n default:\n }\n this._connectionState = value;\n this.inputs.connectionStateChanged(value, oldState, reason);\n }\n\n private readonly transitionToConnectedState = () => {\n // Defensive measure, we should always be in Connecting state when this is called.\n const state = this.pimpl.connectionState;\n assert(state === ConnectionState.Connected, 0x3e5 /* invariant broken */);\n assert(this._connectionState === ConnectionState.CatchingUp, 0x3e6 /* invariant broken */);\n this._connectionState = ConnectionState.Connected;\n this.inputs.connectionStateChanged(ConnectionState.Connected, ConnectionState.CatchingUp, \"caught up\");\n };\n}\n\n/**\n * In the lifetime of a container, the connection will likely disconnect and reconnect periodically.\n * This class ensures that any ops sent by this container instance on previous connection are either\n * sequenced or blocked by the server before emitting the new \"connected\" event and allowing runtime to resubmit ops.\n *\n * Each connection is assigned a clientId by the service, and the connection is book-ended by a Join and a Leave op\n * generated by the service. Due to the distributed nature of the Relay Service, in the case of reconnect we cannot\n * make any assumptions about ordering of operations between the old and new connections - i.e. new Join op could\n * be sequenced before old Leave op (and some acks from pending ops that were in flight when we disconnected).\n *\n * The job of this class is to encapsulate the transition period during reconnect, which is identified by\n * ConnectionState.CatchingUp. Specifically, before moving to Connected state with the new clientId, it ensures that:\n *\n * a. We process the Leave op for the previous clientId. This allows us to properly handle any acks from in-flight ops\n * that got sequenced with the old clientId (we'll recognize them as local ops). After the Leave op, any other\n * pending ops can safely be submitted with the new clientId without fear of duplication in the sequenced op stream.\n *\n * b. We process the Join op for the new clientId (identified when the underlying connection was first established),\n * indicating the service is ready to sequence ops sent with the new clientId.\n *\n * c. We process all ops known at the time the underlying connection was established (so we are \"caught up\")\n *\n * For (a) we give up waiting after some time (same timeout as server uses), and go ahead and transition to Connected.\n *\n * For (b) we log telemetry if it takes too long, but still only transition to Connected when the Join op is processed\n * and we are added to the Quorum.\n *\n * For (c) this is optional behavior, controlled by the parameters of receivedConnectEvent\n */\nclass ConnectionStateHandler implements IConnectionStateHandler {\n private _connectionState = ConnectionState.Disconnected;\n private _pendingClientId: string | undefined;\n private readonly prevClientLeftTimer: Timer;\n private readonly joinOpTimer: Timer;\n private protocol?: IProtocolHandler;\n\n private waitEvent: PerformanceEvent | undefined;\n\n public get connectionState(): ConnectionState {\n return this._connectionState;\n }\n\n private get clientId(): string | undefined {\n return this._clientId;\n }\n\n public get pendingClientId(): string | undefined {\n return this._pendingClientId;\n }\n\n constructor(\n private readonly handler: IConnectionStateHandlerInputs,\n private _clientId?: string,\n ) {\n this.prevClientLeftTimer = new Timer(\n // Default is 5 min for which we are going to wait for its own \"leave\" message. This is same as\n // the max time on server after which leave op is sent.\n this.handler.maxClientLeaveWaitTime ?? 300000,\n () => {\n assert(this.connectionState !== ConnectionState.Connected,\n 0x2ac /* \"Connected when timeout waiting for leave from previous session fired!\" */);\n this.applyForConnectedState(\"timeout\");\n },\n );\n\n // Based on recent data, it looks like majority of cases where we get stuck are due to really slow or\n // timing out ops fetches. So attempt recovery infrequently. Also fetch uses 30 second timeout, so\n // if retrying fixes the problem, we should not see these events.\n this.joinOpTimer = new Timer(\n JoinOpTimeoutMs,\n () => {\n // I've observed timer firing within couple ms from disconnect event, looks like\n // queued timer callback is not cancelled if timer is cancelled while callback sits in the queue.\n if (this.connectionState !== ConnectionState.CatchingUp) {\n return;\n }\n const details = {\n protocolInitialized: this.protocol !== undefined,\n pendingClientId: this.pendingClientId,\n clientJoined: this.hasMember(this.pendingClientId),\n waitingForLeaveOp: this.waitingForLeaveOp,\n };\n this.handler.logConnectionIssue(\"NoJoinOp\", details);\n },\n );\n }\n\n private startJoinOpTimer() {\n assert(!this.joinOpTimer.hasTimer, 0x234 /* \"has joinOpTimer\" */);\n this.joinOpTimer.start();\n }\n\n private stopJoinOpTimer() {\n assert(this.joinOpTimer.hasTimer, 0x235 /* \"no joinOpTimer\" */);\n this.joinOpTimer.clear();\n }\n\n private get waitingForLeaveOp() {\n return this.prevClientLeftTimer.hasTimer;\n }\n\n public dispose() {\n assert(!this.joinOpTimer.hasTimer, 0x2a5 /* \"join timer\" */);\n this.prevClientLeftTimer.clear();\n }\n\n public containerSaved() {\n // If we were waiting for moving to Connected state, then only apply for state change. Since the container\n // is now saved and we don't have any ops to roundtrip, we can clear the timer and apply for connected state.\n if (this.waitingForLeaveOp) {\n this.prevClientLeftTimer.clear();\n this.applyForConnectedState(\"containerSaved\");\n }\n }\n\n private receivedAddMemberEvent(clientId: string) {\n // This is the only one that requires the pending client ID\n if (clientId === this.pendingClientId) {\n if (this.joinOpTimer.hasTimer) {\n this.stopJoinOpTimer();\n } else {\n // timer has already fired, meaning it took too long to get join on.\n // Record how long it actually took to recover.\n this.handler.logConnectionIssue(\"ReceivedJoinOp\");\n }\n // Start the event in case we are waiting for leave or timeout.\n if (this.waitingForLeaveOp) {\n this.waitEvent = PerformanceEvent.start(this.handler.logger, {\n eventName: \"WaitBeforeClientLeave\",\n details: JSON.stringify({\n waitOnClientId: this._clientId,\n hadOutstandingOps: this.handler.shouldClientJoinWrite(),\n }),\n });\n }\n this.applyForConnectedState(\"addMemberEvent\");\n }\n }\n\n private applyForConnectedState(source: \"removeMemberEvent\" | \"addMemberEvent\" | \"timeout\" | \"containerSaved\") {\n assert(this.protocol !== undefined, 0x236 /* \"In all cases it should be already installed\" */);\n\n assert(!this.waitingForLeaveOp || this.hasMember(this.clientId),\n 0x2e2 /* \"Must only wait for leave message when clientId in quorum\" */);\n\n // Move to connected state only if we are in Connecting state, we have seen our join op\n // and there is no timer running which means we are not waiting for previous client to leave\n // or timeout has occurred while doing so.\n if (this.pendingClientId !== this.clientId\n && this.hasMember(this.pendingClientId)\n && !this.waitingForLeaveOp\n ) {\n this.waitEvent?.end({ source });\n this.setConnectionState(ConnectionState.Connected);\n } else {\n // Adding this event temporarily so that we can get help debugging if something goes wrong.\n this.handler.logger.sendTelemetryEvent({\n eventName: \"connectedStateRejected\",\n category: source === \"timeout\" ? \"error\" : \"generic\",\n details: JSON.stringify({\n source,\n pendingClientId: this.pendingClientId,\n clientId: this.clientId,\n waitingForLeaveOp: this.waitingForLeaveOp,\n clientJoined: this.hasMember(this.pendingClientId),\n }),\n });\n }\n }\n\n private receivedRemoveMemberEvent(clientId: string) {\n // If the client which has left was us, then finish the timer.\n if (this.clientId === clientId) {\n this.prevClientLeftTimer.clear();\n this.applyForConnectedState(\"removeMemberEvent\");\n }\n }\n\n public receivedDisconnectEvent(reason: string) {\n this.setConnectionState(ConnectionState.Disconnected, reason);\n }\n\n /**\n * The \"connect\" event indicates the connection to the Relay Service is live.\n * However, some additional conditions must be met before we can fully transition to\n * \"Connected\" state. This function handles that interim period, known as \"Connecting\" state.\n * @param connectionMode - Read or Write connection\n * @param details - Connection details returned from the Relay Service\n * @param deltaManager - DeltaManager to be used for delaying Connected transition until caught up.\n * If it's undefined, then don't delay and transition to Connected as soon as Leave/Join op are accounted for\n */\n public receivedConnectEvent(\n connectionMode: ConnectionMode,\n details: IConnectionDetails,\n ) {\n const oldState = this._connectionState;\n this._connectionState = ConnectionState.CatchingUp;\n\n const writeConnection = connectionMode === \"write\";\n\n // The following checks are wrong. They are only valid if user has write access to a file.\n // If user lost such access mid-session, user will not be able to get \"write\" connection.\n // assert(!this.handler.shouldClientJoinWrite() || writeConnection,\n // 0x30a /* shouldClientJoinWrite should imply this is a writeConnection */);\n // assert(!this.waitingForLeaveOp || writeConnection,\n // 0x2a6 /* \"waitingForLeaveOp should imply writeConnection (we need to be ready to flush pending ops)\" */);\n\n // Stash the clientID to detect when transitioning from connecting (socket.io channel open) to connected\n // (have received the join message for the client ID)\n // This is especially important in the reconnect case. It's possible there could be outstanding\n // ops sent by this client, so we should keep the old client id until we see our own client's\n // join message. after we see the join message for our new connection with our new client id,\n // we know there can no longer be outstanding ops that we sent with the previous client id.\n this._pendingClientId = details.clientId;\n\n // IMPORTANT: Report telemetry after we set _pendingClientId, but before transitioning to Connected state\n this.handler.connectionStateChanged(ConnectionState.CatchingUp, oldState);\n\n // For write connections, this pending clientId could be in the quorum already (i.e. join op already processed).\n // We are fetching ops from storage in parallel to connecting to Relay Service,\n // and given async processes, it's possible that we have already processed our own join message before\n // connection was fully established.\n // If protocol is not initialized yet, we expect it will process the join op after it's initialized.\n const waitingForJoinOp = writeConnection && !this.hasMember(this._pendingClientId);\n\n if (waitingForJoinOp) {\n // Previous client left, and we are waiting for our own join op. When it is processed we'll join the quorum\n // and attempt to transition to Connected state via receivedAddMemberEvent.\n this.startJoinOpTimer();\n } else if (!this.waitingForLeaveOp) {\n // We're not waiting for Join or Leave op (if read-only connection those don't even apply),\n // go ahead and declare the state to be Connected!\n // If we are waiting for Leave op still, do nothing for now, we will transition to Connected later.\n this.setConnectionState(ConnectionState.Connected);\n }\n // else - We are waiting for Leave op still, do nothing for now, we will transition to Connected later\n }\n\n private setConnectionState(value: ConnectionState.Disconnected, reason: string): void;\n private setConnectionState(value: ConnectionState.Connected): void;\n private setConnectionState(value: ConnectionState.Disconnected | ConnectionState.Connected, reason?: string): void {\n if (this.connectionState === value) {\n // Already in the desired state - exit early\n this.handler.logger.sendErrorEvent({ eventName: \"setConnectionStateSame\", value });\n return;\n }\n\n const oldState = this._connectionState;\n this._connectionState = value;\n let client: ILocalSequencedClient | undefined;\n if (this._clientId !== undefined) {\n client = this.protocol?.quorum?.getMember(this._clientId);\n }\n if (value === ConnectionState.Connected) {\n assert(oldState === ConnectionState.CatchingUp,\n 0x1d8 /* \"Should only transition from Connecting state\" */);\n // Mark our old client should have left in the quorum if it's still there\n if (client !== undefined) {\n client.shouldHaveLeft = true;\n }\n this._clientId = this.pendingClientId;\n } else if (value === ConnectionState.Disconnected) {\n // Clear pending state immediately to prepare for reconnect\n this._pendingClientId = undefined;\n\n if (this.joinOpTimer.hasTimer) {\n this.stopJoinOpTimer();\n }\n\n // Only wait for \"leave\" message if the connected client exists in the quorum and had some non-acked ops\n // Also check if the timer is not already running as\n // we could receive \"Disconnected\" event multiple times without getting connected and in that case we\n // don't want to reset the timer as we still want to wait on original client which started this timer.\n if (client !== undefined\n && this.handler.shouldClientJoinWrite()\n && !this.waitingForLeaveOp // same as !this.prevClientLeftTimer.hasTimer\n ) {\n this.prevClientLeftTimer.restart();\n } else {\n // Adding this event temporarily so that we can get help debugging if something goes wrong.\n this.handler.logger.sendTelemetryEvent({\n eventName: \"noWaitOnDisconnected\",\n details: JSON.stringify({\n clientId: this._clientId,\n inQuorum: client !== undefined,\n waitingForLeaveOp: this.waitingForLeaveOp,\n hadOutstandingOps: this.handler.shouldClientJoinWrite(),\n }),\n });\n }\n }\n\n // Report transition before we propagate event across layers\n this.handler.connectionStateChanged(this._connectionState, oldState, reason);\n }\n\n // Helper method to switch between quorum and audience.\n // Old design was checking only quorum for \"write\" clients.\n // Latest change checks audience for all types of connections.\n protected get membership() {\n return this.protocol?.quorum;\n }\n\n public initProtocol(protocol: IProtocolHandler) {\n this.protocol = protocol;\n\n this.membership?.on(\"addMember\", (clientId) => {\n this.receivedAddMemberEvent(clientId);\n });\n\n this.membership?.on(\"removeMember\", (clientId) => {\n this.receivedRemoveMemberEvent(clientId);\n });\n\n // Very unlikely race condition, but theoretically can happen - our new connection is already\n // summarized and we are loading from such summary.\n if (this.hasMember(this.pendingClientId)) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.receivedAddMemberEvent(this.pendingClientId!);\n }\n\n // if we have a clientId from a previous container we need to wait for its leave message\n if (this.clientId !== undefined && this.hasMember(this.clientId)) {\n this.prevClientLeftTimer.restart();\n }\n }\n\n protected hasMember(clientId?: string) {\n return this.membership?.getMember(clientId ?? \"\") !== undefined;\n }\n}\n"]}
@@ -42,14 +42,19 @@ export interface IContainerConfig {
42
42
  serializedContainerState?: IPendingContainerState;
43
43
  }
44
44
  /**
45
- * Waits until container connects to delta storage and gets up-to-date
45
+ * Waits until container connects to delta storage and gets up-to-date.
46
+ *
46
47
  * Useful when resolving URIs and hitting 404, due to container being loaded from (stale) snapshot and not being
47
48
  * up to date. Host may chose to wait in such case and retry resolving URI.
49
+ *
48
50
  * Warning: Will wait infinitely for connection to establish if there is no connection.
49
51
  * May result in deadlock if Container.disconnect() is called and never followed by a call to Container.connect().
50
- * @returns true: container is up to date, it processed all the ops that were know at the time of first connection
51
- * false: storage does not provide indication of how far the client is. Container processed
52
- * all the ops known to it, but it maybe still behind.
52
+ *
53
+ * @returns `true`: container is up to date, it processed all the ops that were know at the time of first connection.
54
+ *
55
+ * `false`: storage does not provide indication of how far the client is. Container processed all the ops known to it,
56
+ * but it maybe still behind.
57
+ *
53
58
  * @throws an error beginning with `"Container closed"` if the container is closed before it catches up.
54
59
  */
55
60
  export declare function waitContainerToCatchUp(container: IContainer): Promise<boolean>;
@@ -88,10 +93,8 @@ export declare class Container extends EventEmitterWithErrorHandling<IContainerE
88
93
  private setLoaded;
89
94
  get closed(): boolean;
90
95
  private _attachState;
91
- private readonly _storage;
96
+ private readonly storageService;
92
97
  get storage(): IDocumentStorageService;
93
- private _storageService;
94
- private get storageService();
95
98
  private readonly clientDetailsOverride;
96
99
  private readonly _deltaManager;
97
100
  private service;
@@ -132,6 +135,7 @@ export declare class Container extends EventEmitterWithErrorHandling<IContainerE
132
135
  * configuration details returned as part of the initial connection.
133
136
  */
134
137
  get serviceConfiguration(): IClientConfiguration | undefined;
138
+ private _clientId;
135
139
  /**
136
140
  * The server provided id of the client.
137
141
  * Set once this.connected is true, otherwise undefined
@@ -196,14 +200,11 @@ export declare class Container extends EventEmitterWithErrorHandling<IContainerE
196
200
  /**
197
201
  * Load container.
198
202
  *
199
- * @param specifiedVersion - one of the following
200
- * - undefined - fetch latest snapshot
201
- * - otherwise, version sha to load snapshot
203
+ * @param specifiedVersion - Version SHA to load snapshot. If not specified, will fetch the latest snapshot.
202
204
  */
203
205
  private load;
204
206
  private createDetached;
205
207
  private rehydrateDetachedFromSnapshot;
206
- private connectStorageService;
207
208
  private getDocumentAttributes;
208
209
  private initializeProtocolStateFromSnapshot;
209
210
  private initializeProtocolState;
@@ -1 +1 @@
1
- {"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../src/container.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,EACH,QAAQ,EACR,SAAS,EACT,YAAY,EACf,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACH,SAAS,EAET,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,uBAAuB,EAEvB,WAAW,EAEX,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EAGpB,MAAM,uCAAuC,CAAC;AAK/C,OAAO,EAEH,uBAAuB,EACvB,iBAAiB,EACjB,YAAY,EACf,MAAM,oCAAoC,CAAC;AAW5C,OAAO,EAEH,oBAAoB,EACpB,cAAc,EAGd,gBAAgB,EAChB,cAAc,EACd,cAAc,EAGd,yBAAyB,EAOzB,QAAQ,EAGX,MAAM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C,OAAO,CAAC,iBAAiB;IAIzB;;;;;OAKG;IACH,OAAO,CAAC,wBAAwB;CAWnC"}
package/dist/container.js CHANGED
@@ -24,10 +24,8 @@ const deltaManager_1 = require("./deltaManager");
24
24
  const deltaManagerProxy_1 = require("./deltaManagerProxy");
25
25
  const loader_1 = require("./loader");
26
26
  const packageVersion_1 = require("./packageVersion");
27
- const connectionStateHandler_1 = require("./connectionStateHandler");
28
- const retriableDocumentStorageService_1 = require("./retriableDocumentStorageService");
29
- const protocolTreeDocumentStorageService_1 = require("./protocolTreeDocumentStorageService");
30
27
  const containerStorageAdapter_1 = require("./containerStorageAdapter");
28
+ const connectionStateHandler_1 = require("./connectionStateHandler");
31
29
  const utils_1 = require("./utils");
32
30
  const quorum_1 = require("./quorum");
33
31
  const collabWindowTracker_1 = require("./collabWindowTracker");
@@ -38,14 +36,19 @@ const detachedContainerRefSeqNumber = 0;
38
36
  const dirtyContainerEvent = "dirty";
39
37
  const savedContainerEvent = "saved";
40
38
  /**
41
- * Waits until container connects to delta storage and gets up-to-date
39
+ * Waits until container connects to delta storage and gets up-to-date.
40
+ *
42
41
  * Useful when resolving URIs and hitting 404, due to container being loaded from (stale) snapshot and not being
43
42
  * up to date. Host may chose to wait in such case and retry resolving URI.
43
+ *
44
44
  * Warning: Will wait infinitely for connection to establish if there is no connection.
45
45
  * May result in deadlock if Container.disconnect() is called and never followed by a call to Container.connect().
46
- * @returns true: container is up to date, it processed all the ops that were know at the time of first connection
47
- * false: storage does not provide indication of how far the client is. Container processed
48
- * all the ops known to it, but it maybe still behind.
46
+ *
47
+ * @returns `true`: container is up to date, it processed all the ops that were know at the time of first connection.
48
+ *
49
+ * `false`: storage does not provide indication of how far the client is. Container processed all the ops known to it,
50
+ * but it maybe still behind.
51
+ *
49
52
  * @throws an error beginning with `"Container closed"` if the container is closed before it catches up.
50
53
  */
51
54
  async function waitContainerToCatchUp(container) {
@@ -190,9 +193,19 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
190
193
  this.mc = (0, telemetry_utils_1.loggerToMonitoringContext)(telemetry_utils_1.ChildLogger.create(this.subLogger, "Container"));
191
194
  const summarizeProtocolTree = (_a = this.mc.config.getBoolean("Fluid.Container.summarizeProtocolTree")) !== null && _a !== void 0 ? _a : this.loader.services.options.summarizeProtocolTree;
192
195
  this.options = Object.assign(Object.assign({}, this.loader.services.options), { summarizeProtocolTree });
193
- this.connectionStateHandler = new connectionStateHandler_1.ConnectionStateHandler({
194
- quorumClients: () => { var _a; return (_a = this._protocolHandler) === null || _a === void 0 ? void 0 : _a.quorum; },
195
- logConnectionStateChangeTelemetry: (value, oldState, reason) => this.logConnectionStateChangeTelemetry(value, oldState, reason),
196
+ this._deltaManager = this.createDeltaManager();
197
+ this._clientId = (_b = config.serializedContainerState) === null || _b === void 0 ? void 0 : _b.clientId;
198
+ this.connectionStateHandler = (0, connectionStateHandler_1.createConnectionStateHandler)({
199
+ logger: this.mc.logger,
200
+ connectionStateChanged: (value, oldState, reason) => {
201
+ if (value === connectionState_1.ConnectionState.Connected) {
202
+ this._clientId = this.connectionStateHandler.pendingClientId;
203
+ }
204
+ this.logConnectionStateChangeTelemetry(value, oldState, reason);
205
+ if (this._lifecycleState === "loaded") {
206
+ this.propagateConnectionState(false /* initial transition */);
207
+ }
208
+ },
196
209
  shouldClientJoinWrite: () => this._deltaManager.connectionManager.shouldJoinWrite(),
197
210
  maxClientLeaveWaitTime: this.loader.services.options.maxClientLeaveWaitTime,
198
211
  logConnectionIssue: (eventName, details) => {
@@ -200,29 +213,13 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
200
213
  // its own join op. Attempt recovery option.
201
214
  this._deltaManager.logConnectionIssue(Object.assign({ eventName, duration: common_utils_1.performance.now() - this.connectionTransitionTimes[connectionState_1.ConnectionState.CatchingUp] }, (details === undefined ? {} : { details: JSON.stringify(details) })));
202
215
  },
203
- connectionStateChanged: () => {
204
- // Fire events only if container is fully loaded and not closed
205
- if (this._lifecycleState === "loaded") {
206
- this.propagateConnectionState();
207
- }
208
- },
209
- }, this.mc.logger, (_b = config.serializedContainerState) === null || _b === void 0 ? void 0 : _b.clientId);
216
+ }, this.deltaManager, this._clientId);
210
217
  this.on(savedContainerEvent, () => {
211
218
  this.connectionStateHandler.containerSaved();
212
219
  });
213
- this._deltaManager = this.createDeltaManager();
214
- this._storage = new containerStorageAdapter_1.ContainerStorageAdapter(() => {
215
- if (this.attachState !== container_definitions_1.AttachState.Attached) {
216
- if (this.loader.services.detachedBlobStorage !== undefined) {
217
- return new containerStorageAdapter_1.BlobOnlyStorage(this.loader.services.detachedBlobStorage, this.mc.logger);
218
- }
219
- this.mc.logger.sendErrorEvent({
220
- eventName: "NoRealStorageInDetachedContainer",
221
- });
222
- throw new Error("Real storage calls not allowed in Unattached container");
223
- }
224
- return this.storageService;
225
- });
220
+ this.storageService = new containerStorageAdapter_1.ContainerStorageAdapter(this.loader.services.detachedBlobStorage, this.mc.logger, this.options.summarizeProtocolTree === true
221
+ ? () => this.captureProtocolSummary()
222
+ : undefined);
226
223
  const isDomAvailable = typeof document === "object" &&
227
224
  document !== null &&
228
225
  typeof document.addEventListener === "function" &&
@@ -343,7 +340,7 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
343
340
  // Only transition states if currently loading
344
341
  if (this._lifecycleState === "loading") {
345
342
  // Propagate current connection state through the system.
346
- this.propagateConnectionState();
343
+ this.propagateConnectionState(true /* initial transition */);
347
344
  this._lifecycleState = "loaded";
348
345
  }
349
346
  }
@@ -351,13 +348,7 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
351
348
  return (this._lifecycleState === "closing" || this._lifecycleState === "closed");
352
349
  }
353
350
  get storage() {
354
- return this._storage;
355
- }
356
- get storageService() {
357
- if (this._storageService === undefined) {
358
- throw new Error("Attempted to access storageService before it was defined");
359
- }
360
- return this._storageService;
351
+ return this.storageService;
361
352
  }
362
353
  get context() {
363
354
  if (this._context === undefined) {
@@ -398,7 +389,7 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
398
389
  return this.connectionStateHandler.connectionState;
399
390
  }
400
391
  get connected() {
401
- return this.connectionStateHandler.connected;
392
+ return this.connectionStateHandler.connectionState === connectionState_1.ConnectionState.Connected;
402
393
  }
403
394
  /**
404
395
  * Service configuration details. If running in offline mode will be undefined otherwise will contain service
@@ -412,7 +403,7 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
412
403
  * Set once this.connected is true, otherwise undefined
413
404
  */
414
405
  get clientId() {
415
- return this.connectionStateHandler.clientId;
406
+ return this._clientId;
416
407
  }
417
408
  /**
418
409
  * The server provided claims of the client.
@@ -474,7 +465,7 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
474
465
  (0, common_utils_1.assert)(this._lifecycleState === "closed", 0x314 /* Container properly closed */);
475
466
  }
476
467
  closeCore(error) {
477
- var _a, _b, _c, _d;
468
+ var _a, _b, _c;
478
469
  (0, common_utils_1.assert)(!this.closed, 0x315 /* re-entrancy */);
479
470
  try {
480
471
  // Ensure that we raise all key events even if one of these throws
@@ -489,11 +480,11 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
489
480
  (_a = this._protocolHandler) === null || _a === void 0 ? void 0 : _a.close();
490
481
  this.connectionStateHandler.dispose();
491
482
  (_b = this._context) === null || _b === void 0 ? void 0 : _b.dispose(error !== undefined ? new Error(error.message) : undefined);
492
- (_c = this._storageService) === null || _c === void 0 ? void 0 : _c.dispose();
483
+ this.storageService.dispose();
493
484
  // Notify storage about critical errors. They may be due to disconnect between client & server knowledge
494
485
  // about file, like file being overwritten in storage, but client having stale local cache.
495
486
  // Driver need to ensure all caches are cleared on critical errors
496
- (_d = this.service) === null || _d === void 0 ? void 0 : _d.dispose(error);
487
+ (_c = this.service) === null || _c === void 0 ? void 0 : _c.dispose(error);
497
488
  }
498
489
  catch (exception) {
499
490
  this.mc.logger.sendErrorEvent({ eventName: "ContainerCloseException" }, exception);
@@ -580,7 +571,7 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
580
571
  const resolvedUrl = this.service.resolvedUrl;
581
572
  (0, driver_utils_1.ensureFluidResolvedUrl)(resolvedUrl);
582
573
  this._resolvedUrl = resolvedUrl;
583
- await this.connectStorageService();
574
+ await this.storageService.connectToService(this.service);
584
575
  if (hasAttachmentBlobs) {
585
576
  // upload blobs to storage
586
577
  (0, common_utils_1.assert)(!!this.loader.services.detachedBlobStorage, 0x24e /* "assertion for type narrowing" */);
@@ -610,8 +601,6 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
610
601
  }
611
602
  this._attachState = container_definitions_1.AttachState.Attached;
612
603
  this.emit("attached");
613
- // Propagate current connection state through the system.
614
- this.propagateConnectionState();
615
604
  if (!this.closed) {
616
605
  this.resumeInternal({ fetchOpsFromStorage: false, reason: "createDetached" });
617
606
  }
@@ -750,9 +739,7 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
750
739
  /**
751
740
  * Load container.
752
741
  *
753
- * @param specifiedVersion - one of the following
754
- * - undefined - fetch latest snapshot
755
- * - otherwise, version sha to load snapshot
742
+ * @param specifiedVersion - Version SHA to load snapshot. If not specified, will fetch the latest snapshot.
756
743
  */
757
744
  async load(specifiedVersion, loadMode, pendingLocalState) {
758
745
  if (this._resolvedUrl === undefined) {
@@ -775,11 +762,11 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
775
762
  this.connectToDeltaStream(connectionArgs);
776
763
  }
777
764
  if (!pendingLocalState) {
778
- await this.connectStorageService();
765
+ await this.storageService.connectToService(this.service);
779
766
  }
780
767
  else {
781
768
  // if we have pendingLocalState we can load without storage; don't wait for connection
782
- this.connectStorageService().catch((error) => this.close(error));
769
+ this.storageService.connectToService(this.service).catch((error) => this.close(error));
783
770
  }
784
771
  this._attachState = container_definitions_1.AttachState.Attached;
785
772
  // Fetch specified snapshot.
@@ -814,12 +801,16 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
814
801
  }
815
802
  // ...load in the existing quorum
816
803
  // Initialize the protocol handler
817
- this._protocolHandler = pendingLocalState === undefined
818
- ? await this.initializeProtocolStateFromSnapshot(attributes, this.storageService, snapshot) : await this.initializeProtocolState(attributes, {
819
- members: pendingLocalState.protocol.members,
820
- proposals: pendingLocalState.protocol.proposals,
821
- values: pendingLocalState.protocol.values,
822
- });
804
+ if (pendingLocalState === undefined) {
805
+ await this.initializeProtocolStateFromSnapshot(attributes, this.storageService, snapshot);
806
+ }
807
+ else {
808
+ this.initializeProtocolState(attributes, {
809
+ members: pendingLocalState.protocol.members,
810
+ proposals: pendingLocalState.protocol.proposals,
811
+ values: pendingLocalState.protocol.values,
812
+ });
813
+ }
823
814
  const codeDetails = this.getCodeDetailsFromQuorum();
824
815
  await this.instantiateContext(true, // existing
825
816
  codeDetails, snapshot, pendingLocalState === null || pendingLocalState === void 0 ? void 0 : pendingLocalState.pendingRuntimeState);
@@ -873,7 +864,7 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
873
864
  await this.attachDeltaManagerOpHandler(attributes);
874
865
  // Need to just seed the source data in the code quorum. Quorum itself is empty
875
866
  const qValues = (0, quorum_1.initQuorumValuesFromCodeDetails)(source);
876
- this._protocolHandler = await this.initializeProtocolState(attributes, {
867
+ this.initializeProtocolState(attributes, {
877
868
  members: [],
878
869
  proposals: [],
879
870
  values: qValues,
@@ -888,40 +879,22 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
888
879
  delete detachedContainerSnapshot.tree[".hasAttachmentBlobs"];
889
880
  }
890
881
  const snapshotTree = (0, utils_1.getSnapshotTreeFromSerializedContainer)(detachedContainerSnapshot);
891
- this._storage.loadSnapshotForRehydratingContainer(snapshotTree);
892
- const attributes = await this.getDocumentAttributes(this._storage, snapshotTree);
882
+ this.storageService.loadSnapshotForRehydratingContainer(snapshotTree);
883
+ const attributes = await this.getDocumentAttributes(this.storageService, snapshotTree);
893
884
  await this.attachDeltaManagerOpHandler(attributes);
894
885
  // Initialize the protocol handler
895
886
  const baseTree = (0, utils_1.getProtocolSnapshotTree)(snapshotTree);
896
- const qValues = await (0, driver_utils_1.readAndParse)(this._storage, baseTree.blobs.quorumValues);
887
+ const qValues = await (0, driver_utils_1.readAndParse)(this.storageService, baseTree.blobs.quorumValues);
897
888
  const codeDetails = (0, quorum_1.getCodeDetailsFromQuorumValues)(qValues);
898
- this._protocolHandler =
899
- await this.initializeProtocolState(attributes, {
900
- members: [],
901
- proposals: [],
902
- values: codeDetails !== undefined ? (0, quorum_1.initQuorumValuesFromCodeDetails)(codeDetails) : [],
903
- });
889
+ this.initializeProtocolState(attributes, {
890
+ members: [],
891
+ proposals: [],
892
+ values: codeDetails !== undefined ? (0, quorum_1.initQuorumValuesFromCodeDetails)(codeDetails) : [],
893
+ });
904
894
  await this.instantiateContextDetached(true, // existing
905
895
  snapshotTree);
906
896
  this.setLoaded();
907
897
  }
908
- async connectStorageService() {
909
- var _a, _b;
910
- if (this._storageService !== undefined) {
911
- return;
912
- }
913
- (0, common_utils_1.assert)(this.service !== undefined, 0x1ef /* "services must be defined" */);
914
- const storageService = await this.service.connectToStorage();
915
- this._storageService =
916
- new retriableDocumentStorageService_1.RetriableDocumentStorageService(storageService, this.mc.logger);
917
- if (this.options.summarizeProtocolTree === true) {
918
- this.mc.logger.sendTelemetryEvent({ eventName: "summarizeProtocolTreeEnabled" });
919
- this._storageService =
920
- new protocolTreeDocumentStorageService_1.ProtocolTreeStorageService(this._storageService, () => this.captureProtocolSummary());
921
- }
922
- // ensure we did not lose that policy in the process of wrapping
923
- (0, common_utils_1.assert)(((_a = storageService.policies) === null || _a === void 0 ? void 0 : _a.minBlobSize) === ((_b = this.storageService.policies) === null || _b === void 0 ? void 0 : _b.minBlobSize), 0x0e0 /* "lost minBlobSize policy" */);
924
- }
925
898
  async getDocumentAttributes(storage, tree) {
926
899
  if (tree === undefined) {
927
900
  return {
@@ -955,10 +928,9 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
955
928
  (0, driver_utils_1.readAndParse)(storage, baseTree.blobs.quorumValues),
956
929
  ]);
957
930
  }
958
- const protocolHandler = await this.initializeProtocolState(attributes, quorumSnapshot);
959
- return protocolHandler;
931
+ this.initializeProtocolState(attributes, quorumSnapshot);
960
932
  }
961
- async initializeProtocolState(attributes, quorumSnapshot) {
933
+ initializeProtocolState(attributes, quorumSnapshot) {
962
934
  var _a, _b;
963
935
  const protocolHandlerBuilder = (_a = this.protocolHandlerBuilder) !== null && _a !== void 0 ? _a : ((...args) => new protocol_1.ProtocolHandler(...args, new audience_1.Audience()));
964
936
  const protocol = protocolHandlerBuilder(attributes, quorumSnapshot, (key, value) => this.submitMessage(protocol_definitions_1.MessageType.Propose, JSON.stringify({ key, value })), (_b = this._initialClients) !== null && _b !== void 0 ? _b : []);
@@ -987,7 +959,11 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
987
959
  });
988
960
  }
989
961
  });
990
- return protocol;
962
+ // we need to make sure this member get set in a synchronous context,
963
+ // or other things can happen after the object that will be set is created, but not yet set
964
+ // this was breaking this._initialClients handling
965
+ //
966
+ this._protocolHandler = protocol;
991
967
  }
992
968
  captureProtocolSummary() {
993
969
  const quorumSnapshot = this.protocolHandler.snapshot();
@@ -1071,10 +1047,7 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
1071
1047
  this._protocolHandler.audience.addMember(priorClient.clientId, priorClient.client);
1072
1048
  }
1073
1049
  }
1074
- const deltaManagerForCatchingUp = this.mc.config.getBoolean("Fluid.Container.CatchUpBeforeDeclaringConnected") === true ?
1075
- this.deltaManager
1076
- : undefined;
1077
- this.connectionStateHandler.receivedConnectEvent(this.connectionMode, details, deltaManagerForCatchingUp);
1050
+ this.connectionStateHandler.receivedConnectEvent(this.connectionMode, details);
1078
1051
  });
1079
1052
  deltaManager.on("disconnect", (reason) => {
1080
1053
  var _a;
@@ -1134,12 +1107,7 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
1134
1107
  opsBehind = checkpointSequenceNumber - this.deltaManager.lastSequenceNumber;
1135
1108
  }
1136
1109
  }
1137
- if (this.firstConnection) {
1138
- connectionInitiationReason = "InitialConnect";
1139
- }
1140
- else {
1141
- connectionInitiationReason = "AutoReconnect";
1142
- }
1110
+ connectionInitiationReason = this.firstConnection ? "InitialConnect" : "AutoReconnect";
1143
1111
  }
1144
1112
  this.mc.logger.sendPerformanceEvent(Object.assign({ eventName: `ConnectionStateChange_${connectionState_1.ConnectionState[value]}`, from: connectionState_1.ConnectionState[oldState], duration,
1145
1113
  durationFromDisconnected,
@@ -1150,15 +1118,23 @@ class Container extends telemetry_utils_1.EventEmitterWithErrorHandling {
1150
1118
  this.firstConnection = false;
1151
1119
  }
1152
1120
  }
1153
- propagateConnectionState() {
1121
+ propagateConnectionState(initialTransition) {
1154
1122
  var _a;
1123
+ // When container loaded, we want to propagate initial connection state.
1124
+ // After that, we communicate only transitions to Connected & Disconnected states, skipping all other states.
1125
+ // This can be changed in the future, for example we likely should add "CatchingUp" event on Container.
1126
+ if (!initialTransition &&
1127
+ this.connectionState !== connectionState_1.ConnectionState.Connected &&
1128
+ this.connectionState !== connectionState_1.ConnectionState.Disconnected) {
1129
+ return;
1130
+ }
1131
+ const state = this.connectionState === connectionState_1.ConnectionState.Connected;
1155
1132
  const logOpsOnReconnect = this.connectionState === connectionState_1.ConnectionState.Connected &&
1156
1133
  !this.firstConnection &&
1157
1134
  this.connectionMode === "write";
1158
1135
  if (logOpsOnReconnect) {
1159
1136
  this.messageCountAfterDisconnection = 0;
1160
1137
  }
1161
- const state = this.connectionState === connectionState_1.ConnectionState.Connected;
1162
1138
  // Both protocol and context should not be undefined if we got so far.
1163
1139
  this.setContextConnectedState(state, (_a = this._deltaManager.connectionManager.readOnlyInfo.readonly) !== null && _a !== void 0 ? _a : false);
1164
1140
  this.protocolHandler.setConnectionState(state, this.clientId);