cube-js/cube · error · MessageTooLargeError

Cube Store request size of ${formatSize(buffer.length)} exce

Error message

Cube Store request size of ${formatSize(buffer.length)} exceeds the maximum message size of ${formatSize(this.maxMessageSize)}. Reduce the size of the query and of the inline tables it sends, or raise CUBEJS_CUBESTORE_MAX_MESSAGE_SIZE together with CUBESTORE_TRANSPORT_MAX_MESSAGE_SIZE on the Cube Store side.

What it means

The driver enforces a client-side maximum WebSocket message size (CUBEJS_CUBESTORE_MAX_MESSAGE_SIZE). Sending a larger frame would make Cube Store close the connection with an unrelated EPIPE error, so the driver checks first and throws MessageTooLargeError with actionable guidance. Large inline tables in queries are the usual cause.

Source

Thrown at packages/cubejs-cubestore-driver/src/WebSocketConnection.ts:425

      webSocket.fatalError = null;
      this.webSocket = webSocket;
    }

    return this.webSocket!.readyPromise;
  }

  private retryWaitTime() {
    return 1000 * (this.currentConnectionTry + 1);
  }

  private async sendMessage(messageId: number, buffer: Uint8Array): Promise<any> {
    if (buffer.length > this.maxMessageSize) {
      // Cube Store would close the connection on such a message, which shows up
      // as an unrelated `write EPIPE`, so report it before sending anything.
      // This only catches what is over our own limit: Cube Store applies its
      // own, by default stricter, CUBESTORE_TRANSPORT_MAX_MESSAGE_SIZE, and a
      // message it refuses is reported once it closes the connection.
      throw new MessageTooLargeError(
        `Cube Store request size of ${formatSize(buffer.length)} exceeds the maximum message size of ` +
        `${formatSize(this.maxMessageSize)}. Reduce the size of the query and of the inline tables it sends, ` +
        'or raise CUBEJS_CUBESTORE_MAX_MESSAGE_SIZE together with CUBESTORE_TRANSPORT_MAX_MESSAGE_SIZE ' +
        'on the Cube Store side.'
      );
    }

    const socket = await this.initWebSocket();
    return new Promise((resolve, reject) => {
      socket.sentMessages[messageId] = { resolve, reject, buffer, fatalRounds: 0 };

      // If socket is closing this message should be resent
      if (socket.readyState === WebSocket.OPEN) {
        socket.send(buffer, (err) => {
          if (err) {
            // Leave the message registered and let 'close' re-send it over a
            // new connection instead of failing it with the write error.
            socket.terminate();

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Reduce the query size / batch inline tables into smaller chunks
  2. Raise CUBEJS_CUBESTORE_MAX_MESSAGE_SIZE on the Cube side AND CUBESTORE_TRANSPORT_MAX_MESSAGE_SIZE on Cube Store side
  3. Stream/load data via external sources instead of inline tables
  4. Break large loads into multiple smaller uploads

Example fix

// before
driver.query(loadQuery, params, { inlineTables: hugeTables });
// after
tableBatches.chunk(hugeTables, 8_000_000).forEach(batch =>
  driver.query(loadQuery, params, { inlineTables: batch }));
// or set env
// CUBEJS_CUBESTORE_MAX_MESSAGE_SIZE=104857600, CUBESTORE_TRANSPORT_MAX_MESSAGE_SIZE=104857600
Defensive patterns

Strategy: validation

Validate before calling

const MAX = 16 * 1024 * 1024; // match CUBEJS_CUBESTORE_MAX_MESSAGE_SIZE
if (inlineTables) {
  const size = JSON.stringify(inlineTables).length;
  if (size > MAX) throw new Error(`inline tables too large: ${size} > ${MAX}`);
}

Type guard

const fitsMessageSize = (buf, max) => buf.length <= max;

Try / catch

try {
  await driver.query(sql, params, { inlineTables });
} catch (e) {
  if (e.name === 'MessageTooLargeError' || /exceeds the maximum message size/.test(e.message)) {
    return sendInBatches(sql, params, inlineTables);
  }
  throw e;
}

Prevention

When it happens

Trigger: query() serializing a request whose flatbuffer exceeds maxMessageSize — commonly loading large data chunks or sending big inline (limited) tables to Cube Store.

Common situations: High-volume pre-aggregation loads; uploading large arrays as inline tables; default max message size too small for the workload.

Related errors


AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02). Data as JSON: /api/errors/a26a0f4dea0762ee. Report an issue: GitHub.