Skip to content

Commit 2b2ed5f

Browse files
committed
fix: clear interrupted flag after cancel
Clear the interrupted flag after cancelling a statement when using a direct executor. Fixes #1879
1 parent 91f575e commit 2b2ed5f

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcStatement.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.cloud.spanner.jdbc;
1818

19+
import com.google.cloud.spanner.ErrorCode;
1920
import com.google.cloud.spanner.Options;
2021
import com.google.cloud.spanner.Options.QueryOption;
2122
import com.google.cloud.spanner.ReadContext.QueryAnalyzeMode;
@@ -259,6 +260,11 @@ private <T> T doWithStatementTimeout(
259260
connection.recordClientLibLatencyMetric(executionDuration.toMillis());
260261
return result;
261262
} catch (SpannerException spannerException) {
263+
if (spannerException.getErrorCode() == ErrorCode.CANCELLED && this.executingLock != null) {
264+
// Clear the interrupted flag of the thread.
265+
//noinspection ResultOfMethodCallIgnored
266+
Thread.interrupted();
267+
}
262268
throw JdbcSqlExceptionFactory.of(spannerException);
263269
} finally {
264270
if (this.executingLock != null) {

src/test/java/com/google/cloud/spanner/jdbc/JdbcStatementTimeoutTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ public void testCancel() throws Exception {
161161
message instanceof ExecuteSqlRequest
162162
&& ((ExecuteSqlRequest) message).getSql().equals(sql),
163163
5000L);
164-
System.out.println("Cancelling statement");
165164
statement.cancel();
166165
return null;
167166
});

0 commit comments

Comments
 (0)