Skip to content

Commit

Permalink
fix: clear interrupted flag after cancel
Browse files Browse the repository at this point in the history
Clear the interrupted flag after cancelling a statement when using
a direct executor.

Fixes #1879
  • Loading branch information
olavloite committed Dec 26, 2024
1 parent 91f575e commit 2b2ed5f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -259,6 +260,11 @@ private <T> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down

0 comments on commit 2b2ed5f

Please sign in to comment.