diff --git a/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcStatement.java b/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcStatement.java index 5c15f336..7161cc13 100644 --- a/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcStatement.java +++ b/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcStatement.java @@ -16,6 +16,7 @@ package com.google.cloud.spanner.jdbc; +import com.google.cloud.spanner.ErrorCode; import com.google.cloud.spanner.Options; import com.google.cloud.spanner.Options.QueryOption; import com.google.cloud.spanner.ReadContext.QueryAnalyzeMode; @@ -259,6 +260,11 @@ private T doWithStatementTimeout( connection.recordClientLibLatencyMetric(executionDuration.toMillis()); return result; } catch (SpannerException spannerException) { + if (spannerException.getErrorCode() == ErrorCode.CANCELLED && this.executingLock != null) { + // Clear the interrupted flag of the thread. + //noinspection ResultOfMethodCallIgnored + Thread.interrupted(); + } throw JdbcSqlExceptionFactory.of(spannerException); } finally { if (this.executingLock != null) { diff --git a/src/test/java/com/google/cloud/spanner/jdbc/JdbcStatementTimeoutTest.java b/src/test/java/com/google/cloud/spanner/jdbc/JdbcStatementTimeoutTest.java index 2c8c43ca..7ce51d36 100644 --- a/src/test/java/com/google/cloud/spanner/jdbc/JdbcStatementTimeoutTest.java +++ b/src/test/java/com/google/cloud/spanner/jdbc/JdbcStatementTimeoutTest.java @@ -161,7 +161,6 @@ public void testCancel() throws Exception { message instanceof ExecuteSqlRequest && ((ExecuteSqlRequest) message).getSql().equals(sql), 5000L); - System.out.println("Cancelling statement"); statement.cancel(); return null; });