message: Runtime error due to circular references in socket errors
  Closes
diff: @@ -28,6 +28,27 @@ import { ChildLogger } from "@fluidframework/telemetry-utils";
  // Local storage key to disable the BatchManager
  const batchManagerDisabledKey = "FluidDisableBatchManager";
  +// See #8129.
  +// Need to move to common-utils.
  +// Borrowed from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value#examples
  +// Avoids runtime errors with circular references.
  +// Not ideal, as will cut values that are not necessarily circular references.
  +// Could be improved by implementing Node's util.inspect() for browser (minus all the coloring code)
  +const getCircularReplacer = () => {
  + const seen = new WeakSet();
  + return (key: string, value: any): any => {
  + // eslint-disable-next-line no-null/no-null
  + if (typeof value === "object" && value !== null) {
  + if (seen.has(value)) {
  + return "<removed/circular>";
  + }
  + seen.add(value);
  + }
  + // eslint-disable-next-line @typescript-eslint/no-unsafe-return
  + return value;
  + };
  +};
  +
  /**
  * Represents a connection to a stream of delta updates
  */
  @@ -519,7 +540,7 @@ export class DocumentDeltaConnection
  // Websocket errors reported by engine.io-client.
  // They are Error objects with description containing WS error and description = "TransportError"
  // Please see https://github.com/socketio/engine.io-client/blob/7245b80/lib/transport.ts#L44,
  - message = `${message}: ${JSON.stringify(error)}`;
  + message = `${message}: ${JSON.stringify(error, getCircularReplacer())}`;
  } else {
  message = `${message}: [object omitted]`;
  }
  