{"record":{"id":"7724a28176d610dd","repo":"cube-js/cube","slug":"query-has-been-cancelled","errorCode":null,"errorMessage":"Query has been cancelled","messagePattern":"Query has been cancelled","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cubejs-athena-driver/src/AthenaDriver.ts","lineNumber":618,"sourceCode":"          Catalog: this.config.catalog,\n          Database: this.config.database\n        }\n      } : {})\n    };\n    const { QueryExecutionId } = await this.athena.startQueryExecution(request);\n    return { QueryExecutionId: checkNonNullable('StartQueryExecution', QueryExecutionId) };\n  }\n\n  protected async checkStatus(qid: AthenaQueryId): Promise<boolean> {\n    const queryExecution = await this.athena.getQueryExecution(qid);\n\n    const status = queryExecution.QueryExecution?.Status?.State;\n    if (status === 'FAILED') {\n      throw new Error(queryExecution.QueryExecution?.Status?.StateChangeReason);\n    }\n\n    if (status === 'CANCELLED') {\n      throw new Error('Query has been cancelled');\n    }\n\n    return status === 'SUCCEEDED';\n  }\n\n  protected async waitForSuccess(qid: AthenaQueryId, isCancelled?: () => boolean): Promise<void> {\n    const startedTime = Date.now();\n    for (let i = 0; Date.now() - startedTime <= this.config.pollTimeout; i++) {\n      if (isCancelled?.()) {\n        throw new Error('Query was cancelled');\n      }\n      if (await this.checkStatus(qid)) {\n        return;\n      }\n      await pausePromise(\n        Math.min(this.config.pollMaxInterval, 500 * i)\n      );\n    }","sourceCodeStart":600,"sourceCodeEnd":636,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-athena-driver/src/AthenaDriver.ts#L600-L636","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Identify who cancelled the query (check Athena console query history and workgroup settings for cancellation).","Increase this.config.pollTimeout if the driver itself is stopping queries via its timeout path (see 'Athena job timeout reached').","Review Athena workgroup settings (per-query scan limits, auto-termination) and relax if they cancel legitimate queries.","Retry the query if cancellation was transient/manual."],"exampleFix":"// before\nnew AthenaDriver({ pollTimeout: 30000 }); // timeout cancels overlapping in-flight queries\n// after\nnew AthenaDriver({ pollTimeout: 600000, pollMaxInterval: 2000 });","handlingStrategy":"retry","validationCode":"// Check a known query's state before resubmitting\nconst qe = await athena.send(new GetQueryExecutionCommand({ QueryExecutionId: qid }));\nif (qe.QueryExecution?.Status?.State === 'CANCELLED') console.warn('prior run was cancelled');","typeGuard":"function isCancelledError(e: unknown): boolean {\n  return e instanceof Error && e.message === 'Query has been cancelled';\n}","tryCatchPattern":"try {\n  await driver.query(sql);\n} catch (e) {\n  if (isCancelledError(e)) {\n    // resubmit or propagate cancellation upstream\n  } else throw e;\n}","preventionTips":["Raise pollTimeout so the driver's own timeout path doesn't stop still-running queries.","Avoid manually cancelling queries in the Athena console during Cube operation windows.","Review workgroup auto-termination and per-query scan limits."],"tags":["aws","athena","query-cancelled"],"backgroundTag":"query-cancelled","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}