{"record":{"id":"e64f163b1c1670dd","repo":"cube-js/cube","slug":"athena-job-timeout-reached-this-config-polltimeo","errorCode":null,"errorMessage":"Athena job timeout reached ${this.config.pollTimeout}ms","messagePattern":"Athena job timeout reached (.+?)ms","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cubejs-athena-driver/src/AthenaDriver.ts","lineNumber":638,"sourceCode":"\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    }\n    await this.stopQuery(qid);\n    throw new Error(\n      `Athena job timeout reached ${this.config.pollTimeout}ms`\n    );\n  }\n\n  // Best-effort: a failure to stop must never bubble up to the caller,\n  // which has already abandoned the query.\n  protected async stopQuery(qid: AthenaQueryId): Promise<void> {\n    try {\n      await this.athena.stopQueryExecution({ QueryExecutionId: qid.QueryExecutionId });\n    } catch (e) {\n      this.logger?.('Failed to stop Athena query', {\n        queryExecutionId: qid.QueryExecutionId,\n        error: (e as Error).message ?? String(e),\n      });\n    }\n  }\n\n  protected async viewsSchema(tablesSchema: DatabaseStructure): Promise<DatabaseStructure> {","sourceCodeStart":620,"sourceCodeEnd":656,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-athena-driver/src/AthenaDriver.ts#L620-L656","documentation":"waitForSuccess polls Athena until the elapsed time exceeds this.config.pollTimeout; when the loop exits without a SUCCEEDED state, the driver calls stopQuery (best-effort) and throws a timeout error including the configured millisecond value. It means the query ran longer than the driver was willing to wait.","triggerScenarios":"Any Athena query (unload, schema scan, queryColumnTypes) still RUNNING/QUEUED after pollTimeout ms of polling — e.g. default pollTimeout with a large unload or a schema scan over hundreds of tables.","commonSituations":"Large pre-aggregation loads in Athena; deep table scans triggering the tablesSchema/ viewsSchema introspection on schema compile; Athena queue backlogs in busy workgroups making even small queries exceed the timeout.","solutions":["Increase pollTimeout in the AthenaDriver config to cover your longest expected query.","Reduce the cost of schema introspection (restrict the schema option, avoid excessive views) so tablesSchema completes faster.","Optimize the underlying SQL / add Athena partitions to shrink runtime.","Check the Athena workgroup for queuing/concurrency limits that delay execution."],"exampleFix":"// before\nconst driver = new AthenaDriver({ database: 'mydb', S3OutputLocation: 's3://bucket/out/' });\n// after\nconst driver = new AthenaDriver({ database: 'mydb', S3OutputLocation: 's3://bucket/out/', pollTimeout: 600000, pollMaxInterval: 2000 });","handlingStrategy":"validation","validationCode":"// Size your pollTimeout to your slowest query workload\nconst pollTimeout = process.env.ATHENA_POLL_TIMEOUT\n  ? parseInt(process.env.ATHENA_POLL_TIMEOUT, 10)\n  : 600000;\nif (!(pollTimeout > 0)) throw new Error('ATHENA_POLL_TIMEOUT must be positive ms');","typeGuard":"function isAthenaTimeout(e: unknown): boolean {\n  return e instanceof Error && /^Athena job timeout reached \\d+ms$/.test(e.message);\n}","tryCatchPattern":"try {\n  await driver.query(sql);\n} catch (e) {\n  if (isAthenaTimeout(e)) {\n    // consider retrying with larger pollTimeout or optimizing the query\n  } else throw e;\n}","preventionTips":["Set pollTimeout explicitly (e.g. 10 minutes) instead of relying on the default.","Benchmark your heaviest pre-aggregation build and size pollTimeout accordingly.","Limit schema introspection cost by setting the schema option and avoiding unnecessary views.","Partition large tables so Athena scans stay fast."],"tags":["athena","timeout","aws"],"backgroundTag":"query-timeout","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}