Repository navigation
Commit 02506d4
committed
fix(spanner): prevent statement cancellation race in AbstractBaseUnitOfWork
In `AbstractBaseUnitOfWork.executeStatementAsync`, statements are submitted asynchronously to `statementExecutor` before `currentlyRunningStatementFuture` is assigned. Under thread contention, the query RPC can reach the server and trigger `cancel()` before the future is stored, causing `cancel()` to silently drop the cancellation request and resulting in statement timeouts in CI tests such as `StatementTimeoutTest#testCancelReadWriteAutocommitMultipleStatements`.
Fix this by tracking cancellation intent via an `isCancelled` flag guarded by `this`, setting it in `cancel()`, and immediately cancelling the future upon registration if cancellation was already requested.1 parent 89a8268 commit 02506d4
1 file changed
Lines changed: 9 additions & 1 deletion
File tree
- java-spanner/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
108 | 111 | | |
109 | 112 | | |
110 | 113 | | |
| |||
277 | 280 | | |
278 | 281 | | |
279 | 282 | | |
| 283 | + | |
280 | 284 | | |
281 | 285 | | |
282 | 286 | | |
| |||
419 | 423 | | |
420 | 424 | | |
421 | 425 | | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
422 | 429 | | |
423 | 430 | | |
424 | 431 | | |
425 | 432 | | |
426 | 433 | | |
427 | | - | |
| 434 | + | |
428 | 435 | | |
429 | 436 | | |
| 437 | + | |
430 | 438 | | |
431 | 439 | | |
432 | 440 | | |
| |||
0 commit comments