Skip to content

chore(bigquerystorage): fix flaky ConnectionWorkerPoolTest#13662

Merged
lqiu96 merged 3 commits into
mainfrom
fix-issue-13637-java
Jul 6, 2026
Merged

chore(bigquerystorage): fix flaky ConnectionWorkerPoolTest#13662
lqiu96 merged 3 commits into
mainfrom
fix-issue-13637-java

Conversation

@lqiu96

@lqiu96 lqiu96 commented Jul 6, 2026

Copy link
Copy Markdown
Member

Fix ConnectionWorkerPoolTest.testMultiStreamAppend_appendWhileClosing by limiting max connections per region to 5. This prevents the pool from scaling up to 6 connections due to timing-dependent overwhelm of mock connections, when the test expects exactly 5.

Also fix a concurrency issue in FakeBigQueryWriteImpl where requestReceivedInstants ArrayList was accessed concurrently without synchronization, causing ArrayIndexOutOfBoundsException (reported as UNKNOWN RPC error in tests).

Fixes #13637

Fix ConnectionWorkerPoolTest.testMultiStreamAppend_appendWhileClosing by limiting max connections per region to 5. This prevents the pool from scaling up to 6 connections due to timing-dependent overwhelm of mock connections, when the test expects exactly 5.

Also fix a concurrency issue in FakeBigQueryWriteImpl where requestReceivedInstants ArrayList was accessed concurrently without synchronization, causing ArrayIndexOutOfBoundsException (reported as UNKNOWN RPC error in tests).

Fixes #13637

TAG=agy
CONV=79e14d4e-c762-4dad-a0d6-de0dd0e3d3f6

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses concurrency and timing issues in tests by limiting maximum connections in ConnectionWorkerPoolTest and synchronizing access to requestReceivedInstants in FakeBigQueryWriteImpl. However, the feedback highlights that other shared variables in FakeBigQueryWriteImpl, such as recordCount and requests, are still modified concurrently without synchronization, which could lead to race conditions or exceptions.

lqiu96 added 2 commits July 6, 2026 18:44
Improve thread safety of FakeBigQueryWriteImpl by:
- Replacing requestReceivedInstants ArrayList with CopyOnWriteArrayList and removing manual synchronization.
- Replacing recordCount, connectionCount, expectedOffset (long) and responseIndex (int) with AtomicLong/AtomicInteger to avoid race conditions and lost updates.
- Synchronizing the offset verification block to ensure atomic check-and-increment of expectedOffset.

This addresses feedback on PR #13662 regarding potential concurrency issues in the test fake.

TAG=agy
CONV=79e14d4e-c762-4dad-a0d6-de0dd0e3d3f6
…fset verification

Replace the synchronized block in FakeBigQueryWriteImpl offset verification with AtomicLong.compareAndSet. This makes the check-and-increment atomic and lock-free, improving performance and thread safety for concurrent streams. Added comments explaining the approach.

TAG=agy
CONV=79e14d4e-c762-4dad-a0d6-de0dd0e3d3f6
@lqiu96
lqiu96 requested a review from jinseopkim0 July 6, 2026 18:50
@lqiu96
lqiu96 marked this pull request as ready for review July 6, 2026 18:50
@lqiu96
lqiu96 requested review from a team as code owners July 6, 2026 18:50
@lqiu96
lqiu96 merged commit 6567e43 into main Jul 6, 2026
212 checks passed
@lqiu96
lqiu96 deleted the fix-issue-13637-java branch July 6, 2026 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BigQueryStorage Flaky Test: ConnectionWorkerPoolTest.testMultiStreamAppend_appendWhileClosing

2 participants