{"record":{"id":"fad9cb3119c9ff8c","repo":"apache/iceberg","slug":"interrupted-while-checking-if-database-s-exists","errorCode":null,"errorMessage":"Interrupted while checking if database '%s' exists","messagePattern":"Interrupted while checking if database '(.+?)' exists","errorType":"exception","errorClass":"UncheckedInterruptedException","httpStatus":null,"severity":"warning","filePath":"snowflake/src/main/java/org/apache/iceberg/snowflake/JdbcSnowflakeClient.java","lineNumber":174,"sourceCode":"        \"databaseExists requires a DATABASE identifier, got '%s'\",\n        database);\n\n    final String finalQuery = \"SHOW SCHEMAS IN DATABASE IDENTIFIER(?) LIMIT 1\";\n\n    List<SnowflakeIdentifier> schemas;\n    try {\n      schemas =\n          connectionPool.run(\n              conn ->\n                  queryHarness.query(\n                      conn, finalQuery, SCHEMA_RESULT_SET_HANDLER, database.databaseName()));\n    } catch (SQLException e) {\n      if (DATABASE_NOT_FOUND_ERROR_CODES.contains(e.getErrorCode())) {\n        return false;\n      }\n      throw new UncheckedSQLException(e, \"Failed to check if database '%s' exists\", database);\n    } catch (InterruptedException e) {\n      throw new UncheckedInterruptedException(\n          e, \"Interrupted while checking if database '%s' exists\", database);\n    }\n\n    return !schemas.isEmpty();\n  }\n\n  @Override\n  public boolean schemaExists(SnowflakeIdentifier schema) {\n    Preconditions.checkArgument(\n        schema.type() == SnowflakeIdentifier.Type.SCHEMA,\n        \"schemaExists requires a SCHEMA identifier, got '%s'\",\n        schema);\n\n    if (!databaseExists(SnowflakeIdentifier.ofDatabase(schema.databaseName()))) {\n      return false;\n    }\n\n    final String finalQuery = \"SHOW TABLES IN SCHEMA IDENTIFIER(?) LIMIT 1\";","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/snowflake/src/main/java/org/apache/iceberg/snowflake/JdbcSnowflakeClient.java#L156-L192","documentation":"JdbcSnowflakeClient.databaseExists wraps InterruptedException thrown while the JDBC query thread is interrupted into UncheckedInterruptedException. Interruption usually comes from task cancellation or shutdown (e.g. Spark/Flink cancelling a query, or a timeout cancelling the executor). The library re-interrupts/propagates so callers can honor cancellation semantics.","triggerScenarios":"The thread executing databaseExists is interrupted while waiting on the JDBC connection/query result — typically via Future.cancel(true), executor shutdownNow, or query timeouts in Spark/Flink tasks.","commonSituations":"Spark task cancelled due to stage retry or speculative execution, application shutdown during catalog initialization, or a custom executor pool shutting down while catalog calls are in flight.","solutions":["Preserve the interrupt status and stop the current operation gracefully; avoid swallowing InterruptedException","Check what cancelled the task (query timeout, spark speculative execution, shutdown hook) and adjust timeouts","Retry the operation after confirming the cancellation was spurious","Avoid long-running work between submitting catalog calls and awaiting results on interruptible threads"],"exampleFix":"// before\nboolean exists = client.databaseExists(SnowflakeIdentifier.ofDatabase(\"db\"));\n// after\ntry {\n  boolean exists = client.databaseExists(SnowflakeIdentifier.ofDatabase(\"db\"));\n} catch (UncheckedInterruptedException e) {\n  Thread.currentThread().interrupt();\n  throw new IllegalStateException(\"Interrupted checking database existence; aborting\", e);\n}","handlingStrategy":"try-catch","validationCode":"if (Thread.currentThread().isInterrupted()) {\n  throw new InterruptedException(\"Interrupted before databaseExists call\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  client.databaseExists(db);\n} catch (UncheckedInterruptedException e) {\n  Thread.currentThread().interrupt();\n  throw e;\n}","preventionTips":["Always restore the interrupt flag when converting to unchecked exceptions","Avoid running catalog operations on threads that receive cancellation signals mid-flight","Configure speculative execution off for jobs with sensitive catalog operations","Use orderly shutdown hooks instead of shutdownNow on pools performing catalog work"],"tags":["snowflake","interruption","threading"],"backgroundTag":"request-timeout","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}