Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[main->0.27] Port improved connection telemetry #3801

Merged
merged 1 commit into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 46 additions & 9 deletions packages/loader/container-loader/src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ITelemetryBaseLogger,
ITelemetryLogger,
} from "@fluidframework/common-definitions";
import { performance } from "@fluidframework/common-utils";
import { IFluidObject, IRequest, IResponse, IFluidRouter } from "@fluidframework/core-interfaces";
import {
IAudience,
Expand All @@ -29,14 +30,7 @@ import {
IThrottlingWarning,
AttachState,
} from "@fluidframework/container-definitions";
import { performance } from "@fluidframework/common-utils";
import {
ChildLogger,
EventEmitterWithErrorHandling,
PerformanceEvent,
raiseConnectedEvent,
TelemetryLogger,
} from "@fluidframework/telemetry-utils";
import { CreateContainerError, GenericError } from "@fluidframework/container-utils";
import {
IDocumentService,
IDocumentStorageService,
Expand All @@ -56,7 +50,6 @@ import {
combineAppAndProtocolSummary,
readAndParseFromBlobs,
} from "@fluidframework/driver-utils";
import { CreateContainerError } from "@fluidframework/container-utils";
import {
isSystemMessage,
ProtocolOpHandler,
Expand Down Expand Up @@ -85,6 +78,13 @@ import {
TreeEntry,
ISummaryTree,
} from "@fluidframework/protocol-definitions";
import {
ChildLogger,
EventEmitterWithErrorHandling,
PerformanceEvent,
raiseConnectedEvent,
TelemetryLogger,
} from "@fluidframework/telemetry-utils";
import { Audience } from "./audience";
import { ContainerContext } from "./containerContext";
import { debug } from "./debug";
Expand All @@ -98,6 +98,10 @@ import { parseUrl, convertProtocolAndAppSummaryToSnapshotTree } from "./utils";

const PackageNotFactoryError = "Code package does not implement IRuntimeFactory";

interface ILocalSequencedClient extends ISequencedClient {
shouldHaveLeft?: boolean;
}

export interface IContainerConfig {
resolvedUrl?: IResolvedUrl;
canReconnect?: boolean;
Expand Down Expand Up @@ -1391,6 +1395,14 @@ export class Container extends EventEmitterWithErrorHandling<IContainerEvents> i
this._connectionState = value;

if (value === ConnectionState.Connected) {
// Mark our old client should have left in the quorum if it's still there
if (this._clientId !== undefined) {
const client: ILocalSequencedClient | undefined =
this._protocolHandler?.quorum.getMember(this._clientId);
if (client !== undefined) {
client.shouldHaveLeft = true;
}
}
this._clientId = this.pendingClientId;
this._deltaManager.updateQuorumJoin();
} else if (value === ConnectionState.Disconnected) {
Expand Down Expand Up @@ -1451,6 +1463,31 @@ export class Container extends EventEmitterWithErrorHandling<IContainerEvents> i
}

private processRemoteMessage(message: ISequencedDocumentMessage): IProcessMessageResult {
// Check and report if we're getting messages from a clientId that we previously
// flagged as shouldHaveLeft, or from a client that's not in the quorum but should be
if (message.clientId != null) {
let errorMsg: string | undefined;
const client: ILocalSequencedClient | undefined =
this._protocolHandler?.quorum.getMember(message.clientId);
if (client === undefined && message.type !== MessageType.ClientJoin) {
errorMsg = "messageClientIdMissingFromQuorum";
} else if (client?.shouldHaveLeft === true) {
errorMsg = "messageClientIdShouldHaveLeft";
}
if (errorMsg !== undefined) {
const error = new GenericError(
errorMsg,
{
clientId: this._clientId,
messageClientId: message.clientId,
sequenceNumber: message.sequenceNumber,
clientSequenceNumber: message.clientSequenceNumber,
},
);
this.close(CreateContainerError(error));
}
}

const local = this._clientId === message.clientId;

// Forward non system messages to the loaded runtime for processing
Expand Down
2 changes: 2 additions & 0 deletions packages/loader/container-loader/src/deltaManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,8 @@ export class DeltaManager
* @param connection - The newly established connection
*/
private setupNewSuccessfulConnection(connection: DeltaConnection, requestedMode: ConnectionMode) {
// Old connection should have been cleaned up before establishing a new one
assert(this.connection === undefined, "old connection exists on new connection setup");
this.connection = connection;

// Does information in scopes & mode matches?
Expand Down
2 changes: 1 addition & 1 deletion packages/loader/container-utils/src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function messageFromError(error: any) {
/**
* Generic error
*/
class GenericError extends CustomErrorWithProps implements IGenericError {
export class GenericError extends CustomErrorWithProps implements IGenericError {
readonly errorType = ContainerErrorType.genericError;

constructor(
Expand Down