cube-js/cube · error

Query has been cancelled

Error message

Query has been cancelled

What it means

During polling, checkStatus sees the Athena QueryExecution state CANCELLED and throws this error. Athena reports CANCELLED when someone (or a timeout policy) called StopQueryExecution, or the workgroup's auto-termination cancelled it. The driver surfaces it so the caller knows the query will never finish.

Source

Thrown at packages/cubejs-athena-driver/src/AthenaDriver.ts:618

          Catalog: this.config.catalog,
          Database: this.config.database
        }
      } : {})
    };
    const { QueryExecutionId } = await this.athena.startQueryExecution(request);
    return { QueryExecutionId: checkNonNullable('StartQueryExecution', QueryExecutionId) };
  }

  protected async checkStatus(qid: AthenaQueryId): Promise<boolean> {
    const queryExecution = await this.athena.getQueryExecution(qid);

    const status = queryExecution.QueryExecution?.Status?.State;
    if (status === 'FAILED') {
      throw new Error(queryExecution.QueryExecution?.Status?.StateChangeReason);
    }

    if (status === 'CANCELLED') {
      throw new Error('Query has been cancelled');
    }

    return status === 'SUCCEEDED';
  }

  protected async waitForSuccess(qid: AthenaQueryId, isCancelled?: () => boolean): Promise<void> {
    const startedTime = Date.now();
    for (let i = 0; Date.now() - startedTime <= this.config.pollTimeout; i++) {
      if (isCancelled?.()) {
        throw new Error('Query was cancelled');
      }
      if (await this.checkStatus(qid)) {
        return;
      }
      await pausePromise(
        Math.min(this.config.pollMaxInterval, 500 * i)
      );
    }

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Identify who cancelled the query (check Athena console query history and workgroup settings for cancellation).
  2. Increase this.config.pollTimeout if the driver itself is stopping queries via its timeout path (see 'Athena job timeout reached').
  3. Review Athena workgroup settings (per-query scan limits, auto-termination) and relax if they cancel legitimate queries.
  4. Retry the query if cancellation was transient/manual.

Example fix

// before
new AthenaDriver({ pollTimeout: 30000 }); // timeout cancels overlapping in-flight queries
// after
new AthenaDriver({ pollTimeout: 600000, pollMaxInterval: 2000 });
Defensive patterns

Strategy: retry

Validate before calling

// Check a known query's state before resubmitting
const qe = await athena.send(new GetQueryExecutionCommand({ QueryExecutionId: qid }));
if (qe.QueryExecution?.Status?.State === 'CANCELLED') console.warn('prior run was cancelled');

Type guard

function isCancelledError(e: unknown): boolean {
  return e instanceof Error && e.message === 'Query has been cancelled';
}

Try / catch

try {
  await driver.query(sql);
} catch (e) {
  if (isCancelledError(e)) {
    // resubmit or propagate cancellation upstream
  } else throw e;
}

Prevention

When it happens

Trigger: waitForSuccess polls a query id whose Athena state is CANCELLED — typically because stopQuery was invoked (e.g. by another timeout path or orchestrator cancellation), a user cancelled it in the AWS console, or the Athena workgroup cancelled it for exceeding limits.

Common situations: Cube's orchestrator cancels a long-running pre-aggregation query; an operator cancelled the query in the Athena console; workgroup per-query or data-scanned limits triggered auto-cancel.

Related errors


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