Skip to content

Commit b2ad948

Browse files
committed
fix(bigtable): resolve data race in ClientTest
Use CopyOnWriteArrayList instead of ArrayList in FakeBigtableService mock implementation. The mock service receives gRPC requests on gRPC executor threads and adds them to openSessionRequests and vrpcRequests. The test thread reads these lists to verify client payloads. Without proper thread synchronization, visibility and ordering issues can cause the test thread to read a null element during ArrayList.add, resulting in a NullPointerException in testMaterializedViewRequestSent. BUG=b/481669998 TAG=agy CONV=7b193e4d-38f8-450c-8475-0b9ae0d04507
1 parent b6cf4f9 commit b2ad948

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

  • java-bigtable/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/api

java-bigtable/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/api/ClientTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545
import io.grpc.Server;
4646
import io.grpc.stub.StreamObserver;
4747
import java.io.IOException;
48-
import java.util.ArrayList;
4948
import java.util.List;
5049
import java.util.concurrent.CompletableFuture;
50+
import java.util.concurrent.CopyOnWriteArrayList;
5151
import java.util.concurrent.ExecutionException;
5252
import java.util.concurrent.Executors;
5353
import java.util.concurrent.ScheduledExecutorService;
@@ -257,8 +257,8 @@ public void testMaterializedViewRequestSent() throws Exception {
257257
}
258258

259259
class FakeBigtableService extends BigtableGrpc.BigtableImplBase {
260-
private final List<SessionRequest> openSessionRequests = new ArrayList<>();
261-
private final List<SessionRequest> vrpcRequests = new ArrayList<>();
260+
private final List<SessionRequest> openSessionRequests = new CopyOnWriteArrayList<>();
261+
private final List<SessionRequest> vrpcRequests = new CopyOnWriteArrayList<>();
262262

263263
@Override
264264
public void getClientConfiguration(

0 commit comments

Comments
 (0)