Skip to content

Commit 0554607

Browse files
committed
Merge branch 'master' into lincheck-update
2 parents 7c29958 + 2ba5c3d commit 0554607

File tree

5 files changed

+37
-46
lines changed

5 files changed

+37
-46
lines changed

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ For a guided tour, take a look at the [quick start
4444
guide](https://grpc.io/docs/languages/java/quickstart) or the more explanatory [gRPC
4545
basics](https://grpc.io/docs/languages/java/basics).
4646

47-
The [examples](https://github.com/grpc/grpc-java/tree/v1.74.0/examples) and the
48-
[Android example](https://github.com/grpc/grpc-java/tree/v1.74.0/examples/android)
47+
The [examples](https://github.com/grpc/grpc-java/tree/v1.75.0/examples) and the
48+
[Android example](https://github.com/grpc/grpc-java/tree/v1.75.0/examples/android)
4949
are standalone projects that showcase the usage of gRPC.
5050

5151
Download
@@ -56,18 +56,18 @@ Download [the JARs][]. Or for Maven with non-Android, add to your `pom.xml`:
5656
<dependency>
5757
<groupId>io.grpc</groupId>
5858
<artifactId>grpc-netty-shaded</artifactId>
59-
<version>1.74.0</version>
59+
<version>1.75.0</version>
6060
<scope>runtime</scope>
6161
</dependency>
6262
<dependency>
6363
<groupId>io.grpc</groupId>
6464
<artifactId>grpc-protobuf</artifactId>
65-
<version>1.74.0</version>
65+
<version>1.75.0</version>
6666
</dependency>
6767
<dependency>
6868
<groupId>io.grpc</groupId>
6969
<artifactId>grpc-stub</artifactId>
70-
<version>1.74.0</version>
70+
<version>1.75.0</version>
7171
</dependency>
7272
<dependency> <!-- necessary for Java 9+ -->
7373
<groupId>org.apache.tomcat</groupId>
@@ -79,18 +79,18 @@ Download [the JARs][]. Or for Maven with non-Android, add to your `pom.xml`:
7979

8080
Or for Gradle with non-Android, add to your dependencies:
8181
```gradle
82-
runtimeOnly 'io.grpc:grpc-netty-shaded:1.74.0'
83-
implementation 'io.grpc:grpc-protobuf:1.74.0'
84-
implementation 'io.grpc:grpc-stub:1.74.0'
82+
runtimeOnly 'io.grpc:grpc-netty-shaded:1.75.0'
83+
implementation 'io.grpc:grpc-protobuf:1.75.0'
84+
implementation 'io.grpc:grpc-stub:1.75.0'
8585
compileOnly 'org.apache.tomcat:annotations-api:6.0.53' // necessary for Java 9+
8686
```
8787

8888
For Android client, use `grpc-okhttp` instead of `grpc-netty-shaded` and
8989
`grpc-protobuf-lite` instead of `grpc-protobuf`:
9090
```gradle
91-
implementation 'io.grpc:grpc-okhttp:1.74.0'
92-
implementation 'io.grpc:grpc-protobuf-lite:1.74.0'
93-
implementation 'io.grpc:grpc-stub:1.74.0'
91+
implementation 'io.grpc:grpc-okhttp:1.75.0'
92+
implementation 'io.grpc:grpc-protobuf-lite:1.75.0'
93+
implementation 'io.grpc:grpc-stub:1.75.0'
9494
compileOnly 'org.apache.tomcat:annotations-api:6.0.53' // necessary for Java 9+
9595
```
9696

@@ -99,7 +99,7 @@ For [Bazel](https://bazel.build), you can either
9999
(with the GAVs from above), or use `@io_grpc_grpc_java//api` et al (see below).
100100

101101
[the JARs]:
102-
https://search.maven.org/search?q=g:io.grpc%20AND%20v:1.74.0
102+
https://search.maven.org/search?q=g:io.grpc%20AND%20v:1.75.0
103103

104104
Development snapshots are available in [Sonatypes's snapshot
105105
repository](https://central.sonatype.com/repository/maven-snapshots/).
@@ -131,7 +131,7 @@ For protobuf-based codegen integrated with the Maven build system, you can use
131131
<configuration>
132132
<protocArtifact>com.google.protobuf:protoc:3.25.5:exe:${os.detected.classifier}</protocArtifact>
133133
<pluginId>grpc-java</pluginId>
134-
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.74.0:exe:${os.detected.classifier}</pluginArtifact>
134+
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.75.0:exe:${os.detected.classifier}</pluginArtifact>
135135
</configuration>
136136
<executions>
137137
<execution>
@@ -161,7 +161,7 @@ protobuf {
161161
}
162162
plugins {
163163
grpc {
164-
artifact = 'io.grpc:protoc-gen-grpc-java:1.74.0'
164+
artifact = 'io.grpc:protoc-gen-grpc-java:1.75.0'
165165
}
166166
}
167167
generateProtoTasks {
@@ -194,7 +194,7 @@ protobuf {
194194
}
195195
plugins {
196196
grpc {
197-
artifact = 'io.grpc:protoc-gen-grpc-java:1.74.0'
197+
artifact = 'io.grpc:protoc-gen-grpc-java:1.75.0'
198198
}
199199
}
200200
generateProtoTasks {

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ signature-java = "org.codehaus.mojo.signature:java18:1.0"
111111
tomcat-embed-core = "org.apache.tomcat.embed:tomcat-embed-core:10.1.31"
112112
tomcat-embed-core9 = "org.apache.tomcat.embed:tomcat-embed-core:9.0.89"
113113
truth = "com.google.truth:truth:1.4.4"
114-
undertow-servlet22 = "io.undertow:undertow-servlet:2.2.32.Final"
114+
undertow-servlet22 = "io.undertow:undertow-servlet:2.2.37.Final"
115115
undertow-servlet = "io.undertow:undertow-servlet:2.3.18.Final"
116116

117117
# Do not update: Pinned to the last version supporting Java 8.

servlet/src/main/java/io/grpc/servlet/AsyncServletOutputStreamWriter.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
import io.grpc.InternalLogId;
2727
import io.grpc.servlet.ServletServerStream.ServletTransportState;
2828
import java.io.IOException;
29-
import java.time.Duration;
3029
import java.util.Queue;
3130
import java.util.concurrent.ConcurrentLinkedQueue;
31+
import java.util.concurrent.TimeUnit;
3232
import java.util.concurrent.atomic.AtomicReference;
3333
import java.util.concurrent.locks.LockSupport;
3434
import java.util.function.BiFunction;
@@ -128,7 +128,7 @@ public void finest(String str, Object... params) {
128128
log.fine("call completed");
129129
});
130130
};
131-
this.isReady = () -> outputStream.isReady();
131+
this.isReady = outputStream::isReady;
132132
}
133133

134134
/**
@@ -173,7 +173,9 @@ void complete() {
173173
/** Called from the container thread {@link javax.servlet.WriteListener#onWritePossible()}. */
174174
void onWritePossible() throws IOException {
175175
log.finest("onWritePossible: ENTRY. The servlet output stream becomes ready");
176-
assureReadyAndDrainedTurnsFalse();
176+
if (writeState.get().readyAndDrained) {
177+
assureReadyAndDrainedTurnsFalse();
178+
}
177179
while (isReady.getAsBoolean()) {
178180
WriteState curState = writeState.get();
179181

@@ -200,11 +202,9 @@ private void assureReadyAndDrainedTurnsFalse() {
200202
// readyAndDrained should have been set to false already.
201203
// Just in case due to a race condition readyAndDrained is still true at this moment and is
202204
// being set to false by runOrBuffer() concurrently.
205+
parkingThread = Thread.currentThread();
203206
while (writeState.get().readyAndDrained) {
204-
parkingThread = Thread.currentThread();
205-
// Try to sleep for an extremely long time to avoid writeState being changed at exactly
206-
// the time when sleep time expires (in extreme scenario, such as #9917).
207-
LockSupport.parkNanos(Duration.ofHours(1).toNanos()); // should return immediately
207+
LockSupport.parkNanos(TimeUnit.MINUTES.toNanos(1)); // should return immediately
208208
}
209209
parkingThread = null;
210210
}
@@ -254,7 +254,7 @@ interface ActionItem {
254254
@VisibleForTesting // Lincheck test can not run with java.util.logging dependency.
255255
interface Log {
256256
default boolean isLoggable(Level level) {
257-
return false;
257+
return false;
258258
}
259259

260260
default void fine(String str, Object...params) {}

servlet/src/main/java/io/grpc/servlet/ServletAdapter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ private static final class GrpcAsyncListener implements AsyncListener {
215215
}
216216

217217
@Override
218-
public void onComplete(AsyncEvent event) {}
218+
public void onComplete(AsyncEvent event) {
219+
stream.asyncCompleted = true;
220+
}
219221

220222
@Override
221223
public void onTimeout(AsyncEvent event) {

servlet/src/main/java/io/grpc/servlet/ServletServerStream.java

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import io.grpc.InternalLogId;
3131
import io.grpc.Metadata;
3232
import io.grpc.Status;
33-
import io.grpc.Status.Code;
3433
import io.grpc.internal.AbstractServerStream;
3534
import io.grpc.internal.GrpcUtil;
3635
import io.grpc.internal.SerializingExecutor;
@@ -43,8 +42,6 @@
4342
import java.util.Collections;
4443
import java.util.HashMap;
4544
import java.util.Map;
46-
import java.util.concurrent.CountDownLatch;
47-
import java.util.concurrent.TimeUnit;
4845
import java.util.function.Supplier;
4946
import java.util.logging.Logger;
5047
import javax.annotation.Nullable;
@@ -58,12 +55,15 @@ final class ServletServerStream extends AbstractServerStream {
5855

5956
private final ServletTransportState transportState;
6057
private final Sink sink = new Sink();
61-
private final AsyncContext asyncCtx;
6258
private final HttpServletResponse resp;
6359
private final Attributes attributes;
6460
private final String authority;
6561
private final InternalLogId logId;
6662
private final AsyncServletOutputStreamWriter writer;
63+
/**
64+
* If the async servlet operation has been completed.
65+
*/
66+
volatile boolean asyncCompleted = false;
6767

6868
ServletServerStream(
6969
AsyncContext asyncCtx,
@@ -78,7 +78,6 @@ final class ServletServerStream extends AbstractServerStream {
7878
this.attributes = attributes;
7979
this.authority = authority;
8080
this.logId = logId;
81-
this.asyncCtx = asyncCtx;
8281
this.resp = (HttpServletResponse) asyncCtx.getResponse();
8382
this.writer = new AsyncServletOutputStreamWriter(
8483
asyncCtx, transportState, logId);
@@ -292,24 +291,14 @@ public void writeTrailers(Metadata trailers, boolean headersSent, Status status)
292291

293292
@Override
294293
public void cancel(Status status) {
295-
if (resp.isCommitted() && Code.DEADLINE_EXCEEDED == status.getCode()) {
296-
return; // let the servlet timeout, the container will sent RST_STREAM automatically
297-
}
298294
transportState.runOnTransportThread(() -> transportState.transportReportStatus(status));
299-
// There is no way to RST_STREAM with CANCEL code, so write trailers instead
300-
close(Status.CANCELLED.withDescription("Servlet stream cancelled")
301-
.withCause(status.asRuntimeException()),
302-
new Metadata());
303-
CountDownLatch countDownLatch = new CountDownLatch(1);
304-
transportState.runOnTransportThread(() -> {
305-
asyncCtx.complete();
306-
countDownLatch.countDown();
307-
});
308-
try {
309-
countDownLatch.await(5, TimeUnit.SECONDS);
310-
} catch (InterruptedException e) {
311-
Thread.currentThread().interrupt();
295+
if (asyncCompleted) {
296+
logger.fine("ignore cancel as already completed");
297+
return;
312298
}
299+
// There is no way to RST_STREAM with CANCEL code, so write trailers instead
300+
close(status, new Metadata());
301+
// close() calls writeTrailers(), which calls AsyncContext.complete()
313302
}
314303
}
315304

0 commit comments

Comments
 (0)