Skip to content

Commit d3c77f2

Browse files
graememorgandapengzhang0
authored andcommitted
all: Add suppressions for GuardedBy violations
This supports releasing a new version of GuardedBy which finds more mistakes than it used to. Filed #6578 to try to clean up the suppressions.
1 parent 1980523 commit d3c77f2

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

core/src/main/java/io/grpc/internal/RetriableStream.java

+15
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ abstract class RetriableStream<ReqT> implements ClientStream {
121121
this.throttle = throttle;
122122
}
123123

124+
@SuppressWarnings("GuardedBy")
124125
@Nullable // null if already committed
125126
@CheckReturnValue
126127
private Runnable commit(final Substream winningSubstream) {
@@ -138,6 +139,8 @@ private Runnable commit(final Substream winningSubstream) {
138139

139140
final Future<?> retryFuture;
140141
if (scheduledRetry != null) {
142+
// TODO(b/145386688): This access should be guarded by 'this.scheduledRetry.lock'; instead
143+
// found: 'this.lock'
141144
retryFuture = scheduledRetry.markCancelled();
142145
scheduledRetry = null;
143146
} else {
@@ -146,6 +149,8 @@ private Runnable commit(final Substream winningSubstream) {
146149
// cancel the scheduled hedging if it is scheduled prior to the commitment
147150
final Future<?> hedgingFuture;
148151
if (scheduledHedging != null) {
152+
// TODO(b/145386688): This access should be guarded by 'this.scheduledHedging.lock'; instead
153+
// found: 'this.lock'
149154
hedgingFuture = scheduledHedging.markCancelled();
150155
scheduledHedging = null;
151156
} else {
@@ -338,6 +343,7 @@ public void runWith(Substream substream) {
338343
drain(substream);
339344
}
340345

346+
@SuppressWarnings("GuardedBy")
341347
private void pushbackHedging(@Nullable Integer delayMillis) {
342348
if (delayMillis == null) {
343349
return;
@@ -356,6 +362,8 @@ private void pushbackHedging(@Nullable Integer delayMillis) {
356362
return;
357363
}
358364

365+
// TODO(b/145386688): This access should be guarded by 'this.scheduledHedging.lock'; instead
366+
// found: 'this.lock'
359367
futureToBeCancelled = scheduledHedging.markCancelled();
360368
scheduledHedging = future = new FutureCanceller(lock);
361369
}
@@ -381,6 +389,7 @@ private final class HedgingRunnable implements Runnable {
381389
public void run() {
382390
callExecutor.execute(
383391
new Runnable() {
392+
@SuppressWarnings("GuardedBy")
384393
@Override
385394
public void run() {
386395
// It's safe to read state.hedgingAttemptCount here.
@@ -392,6 +401,9 @@ public void run() {
392401
FutureCanceller future = null;
393402

394403
synchronized (lock) {
404+
// TODO(b/145386688): This access should be guarded by
405+
// 'HedgingRunnable.this.scheduledHedgingRef.lock'; instead found:
406+
// 'RetriableStream.this.lock'
395407
if (scheduledHedgingRef.isCancelled()) {
396408
cancelled = true;
397409
} else {
@@ -695,10 +707,13 @@ private boolean hasPotentialHedging(State state) {
695707
&& !state.hedgingFrozen;
696708
}
697709

710+
@SuppressWarnings("GuardedBy")
698711
private void freezeHedging() {
699712
Future<?> futureToBeCancelled = null;
700713
synchronized (lock) {
701714
if (scheduledHedging != null) {
715+
// TODO(b/145386688): This access should be guarded by 'this.scheduledHedging.lock'; instead
716+
// found: 'this.lock'
702717
futureToBeCancelled = scheduledHedging.markCancelled();
703718
scheduledHedging = null;
704719
}

cronet/src/main/java/io/grpc/cronet/CronetClientTransport.java

+3
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,12 @@ public void run() {
149149
return new StartCallback().clientStream;
150150
}
151151

152+
@SuppressWarnings("GuardedBy")
152153
@GuardedBy("lock")
153154
private void startStream(CronetClientStream stream) {
154155
streams.add(stream);
156+
// TODO(b/145386688): This access should be guarded by 'stream.transportState().lock'; instead
157+
// found: 'this.lock'
155158
stream.transportState().start(streamFactory);
156159
}
157160

okhttp/src/main/java/io/grpc/okhttp/OkHttpClientStream.java

+9
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,13 @@ public TransportState(
256256
tag = PerfMark.createTag(methodName);
257257
}
258258

259+
@SuppressWarnings("GuardedBy")
259260
@GuardedBy("lock")
260261
public void start(int streamId) {
261262
checkState(id == ABSENT_ID, "the stream has been started with id %s", streamId);
262263
id = streamId;
264+
// TODO(b/145386688): This access should be guarded by 'OkHttpClientStream.this.state.lock';
265+
// instead found: 'this.lock'
263266
state.onStreamAllocated();
264267

265268
if (canStart) {
@@ -365,6 +368,7 @@ private void onEndOfStream() {
365368
}
366369
}
367370

371+
@SuppressWarnings("GuardedBy")
368372
@GuardedBy("lock")
369373
private void cancel(Status reason, boolean stopDelivery, Metadata trailers) {
370374
if (cancelSent) {
@@ -373,6 +377,8 @@ private void cancel(Status reason, boolean stopDelivery, Metadata trailers) {
373377
cancelSent = true;
374378
if (canStart) {
375379
// stream is pending.
380+
// TODO(b/145386688): This access should be guarded by 'this.transport.lock'; instead found:
381+
// 'this.lock'
376382
transport.removePendingStream(OkHttpClientStream.this);
377383
// release holding data, so they can be GCed or returned to pool earlier.
378384
requestHeaders = null;
@@ -406,6 +412,7 @@ private void sendBuffer(Buffer buffer, boolean endOfStream, boolean flush) {
406412
}
407413
}
408414

415+
@SuppressWarnings("GuardedBy")
409416
@GuardedBy("lock")
410417
private void streamReady(Metadata metadata, String path) {
411418
requestHeaders =
@@ -416,6 +423,8 @@ private void streamReady(Metadata metadata, String path) {
416423
userAgent,
417424
useGet,
418425
transport.isUsingPlaintext());
426+
// TODO(b/145386688): This access should be guarded by 'this.transport.lock'; instead found:
427+
// 'this.lock'
419428
transport.streamReadyToStart(OkHttpClientStream.this);
420429
}
421430

okhttp/src/main/java/io/grpc/okhttp/OkHttpClientTransport.java

+9
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,15 @@ void streamReadyToStart(OkHttpClientStream clientStream) {
424424
}
425425
}
426426

427+
@SuppressWarnings("GuardedBy")
427428
@GuardedBy("lock")
428429
private void startStream(OkHttpClientStream stream) {
429430
Preconditions.checkState(
430431
stream.id() == OkHttpClientStream.ABSENT_ID, "StreamId already assigned");
431432
streams.put(nextStreamId, stream);
432433
setInUse(stream);
434+
// TODO(b/145386688): This access should be guarded by 'stream.transportState().lock'; instead
435+
// found: 'this.lock'
433436
stream.transportState().start(nextStreamId);
434437
// For unary and server streaming, there will be a data frame soon, no need to flush the header.
435438
if ((stream.getType() != MethodType.UNARY && stream.getType() != MethodType.SERVER_STREAMING)
@@ -1111,6 +1114,7 @@ public void run() {
11111114
/**
11121115
* Handle an HTTP2 DATA frame.
11131116
*/
1117+
@SuppressWarnings("GuardedBy")
11141118
@Override
11151119
public void data(boolean inFinished, int streamId, BufferedSource in, int length)
11161120
throws IOException {
@@ -1136,6 +1140,8 @@ public void data(boolean inFinished, int streamId, BufferedSource in, int length
11361140
PerfMark.event("OkHttpClientTransport$ClientFrameHandler.data",
11371141
stream.transportState().tag());
11381142
synchronized (lock) {
1143+
// TODO(b/145386688): This access should be guarded by 'stream.transportState().lock';
1144+
// instead found: 'OkHttpClientTransport.this.lock'
11391145
stream.transportState().transportDataReceived(buf, inFinished);
11401146
}
11411147
}
@@ -1153,6 +1159,7 @@ public void data(boolean inFinished, int streamId, BufferedSource in, int length
11531159
/**
11541160
* Handle HTTP2 HEADER and CONTINUATION frames.
11551161
*/
1162+
@SuppressWarnings("GuardedBy")
11561163
@Override
11571164
public void headers(boolean outFinished,
11581165
boolean inFinished,
@@ -1186,6 +1193,8 @@ public void headers(boolean outFinished,
11861193
if (failedStatus == null) {
11871194
PerfMark.event("OkHttpClientTransport$ClientFrameHandler.headers",
11881195
stream.transportState().tag());
1196+
// TODO(b/145386688): This access should be guarded by 'stream.transportState().lock';
1197+
// instead found: 'OkHttpClientTransport.this.lock'
11891198
stream.transportState().transportHeadersReceived(headerBlock, inFinished);
11901199
} else {
11911200
if (!inFinished) {

0 commit comments

Comments
 (0)