Repository navigation
test(spanner): unflake ReadWriteTransactionWithInlineBeginTest - #14888
Conversation
Synchronize on the prefetch request() call instead of ExecuteSqlRequest mock server receipt to prevent close() from racing with stream registration.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates a test in ReadWriteTransactionWithInlineBeginTest.java to use a CountDownLatch (streamRegisteredLatch) to synchronize and wait for the stream to be registered before closing the result set, replacing a wait for mock Spanner requests. However, calling streamRegisteredLatch.await(...) throws a checked InterruptedException which is unhandled in the current lambda context, causing a compilation error. It is recommended to wrap this call in a try-catch block and restore the thread's interrupted status.
There was a problem hiding this comment.
Code Review
This pull request updates a test in ReadWriteTransactionWithInlineBeginTest.java to use a CountDownLatch (streamRegisteredLatch) to synchronize the stream registration before closing the result set, replacing a time-based wait for requests. However, calling streamRegisteredLatch.await throws a checked InterruptedException which is not handled inside the lambda expression, leading to a compilation error. It is recommended to wrap this call in a try-catch block, restore the interrupted status, and throw a RuntimeException to ensure the test compiles and fails correctly if interrupted.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request improves synchronization in the ReadWriteTransactionWithInlineBeginTest class by introducing a streamRegisteredLatch and tracking the consumerThread to prevent race conditions and self-deadlocks during stream cancellation. The reviewer recommends improving the handling of InterruptedException within the cancel method by throwing a RuntimeException instead of swallowing it, which ensures that the test fails immediately and clearly upon interruption.
Problem
ReadWriteTransactionWithInlineBeginTest#closeBeforeTransactionIdReturnedDoesNotRaceWithCancelledConsumersynchronizes onmockSpanner.waitForRequestsToContain(ExecuteSqlRequest.class), but the server sees this insiderequest.start(...)beforesetCall()andResumableStreamIterator.setStream()complete, causing a race whereresultSet.close()cancels nothing and the consumer thread deadlocks awaiting its own cancellation latch (TimeoutException).Solution
request()call viastreamRegisteredLatch.countDown(), which only executes aftersetStream()returns, guaranteeing thatresultSet.close()cancels the registered stream from the closing thread.consumerThreadand only awaitconsumerFinishedNextLatchinsidecancel()when invoked from an external thread, preventing self-deadlock ifcancel()is ever called on the consumer thread itself.