Skip to content

Commit bb47680

Browse files
all: Add suppressions for GuardedBy violations (#7291)
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. Co-authored-by: Graeme Morgan <[email protected]>
1 parent 62e8655 commit bb47680

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
@@ -142,9 +142,12 @@ public void run() {
142142
return new StartCallback().clientStream;
143143
}
144144

145+
@SuppressWarnings("GuardedBy")
145146
@GuardedBy("lock")
146147
private void startStream(CronetClientStream stream) {
147148
streams.add(stream);
149+
// TODO(b/145386688): This access should be guarded by 'stream.transportState().lock'; instead
150+
// found: 'this.lock'
148151
stream.transportState().start(streamFactory);
149152
}
150153

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

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

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

264267
if (canStart) {
@@ -364,6 +367,7 @@ private void onEndOfStream() {
364367
}
365368
}
366369

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

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

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

+9
Original file line numberDiff line numberDiff line change
@@ -419,12 +419,15 @@ void streamReadyToStart(OkHttpClientStream clientStream) {
419419
}
420420
}
421421

422+
@SuppressWarnings("GuardedBy")
422423
@GuardedBy("lock")
423424
private void startStream(OkHttpClientStream stream) {
424425
Preconditions.checkState(
425426
stream.id() == OkHttpClientStream.ABSENT_ID, "StreamId already assigned");
426427
streams.put(nextStreamId, stream);
427428
setInUse(stream);
429+
// TODO(b/145386688): This access should be guarded by 'stream.transportState().lock'; instead
430+
// found: 'this.lock'
428431
stream.transportState().start(nextStreamId);
429432
// For unary and server streaming, there will be a data frame soon, no need to flush the header.
430433
if ((stream.getType() != MethodType.UNARY && stream.getType() != MethodType.SERVER_STREAMING)
@@ -1106,6 +1109,7 @@ public void run() {
11061109
/**
11071110
* Handle an HTTP2 DATA frame.
11081111
*/
1112+
@SuppressWarnings("GuardedBy")
11091113
@Override
11101114
public void data(boolean inFinished, int streamId, BufferedSource in, int length)
11111115
throws IOException {
@@ -1131,6 +1135,8 @@ public void data(boolean inFinished, int streamId, BufferedSource in, int length
11311135
PerfMark.event("OkHttpClientTransport$ClientFrameHandler.data",
11321136
stream.transportState().tag());
11331137
synchronized (lock) {
1138+
// TODO(b/145386688): This access should be guarded by 'stream.transportState().lock';
1139+
// instead found: 'OkHttpClientTransport.this.lock'
11341140
stream.transportState().transportDataReceived(buf, inFinished);
11351141
}
11361142
}
@@ -1148,6 +1154,7 @@ public void data(boolean inFinished, int streamId, BufferedSource in, int length
11481154
/**
11491155
* Handle HTTP2 HEADER and CONTINUATION frames.
11501156
*/
1157+
@SuppressWarnings("GuardedBy")
11511158
@Override
11521159
public void headers(boolean outFinished,
11531160
boolean inFinished,
@@ -1181,6 +1188,8 @@ public void headers(boolean outFinished,
11811188
if (failedStatus == null) {
11821189
PerfMark.event("OkHttpClientTransport$ClientFrameHandler.headers",
11831190
stream.transportState().tag());
1191+
// TODO(b/145386688): This access should be guarded by 'stream.transportState().lock';
1192+
// instead found: 'OkHttpClientTransport.this.lock'
11841193
stream.transportState().transportHeadersReceived(headerBlock, inFinished);
11851194
} else {
11861195
if (!inFinished) {

0 commit comments

Comments
 (0)