Skip to content

Commit b76d860

Browse files
committed
ignore IllegalStateException from asyncContext.complete()
1 parent 176f3ee commit b76d860

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ public void finest(String str, Object... params) {
124124
transportState.runOnTransportThread(
125125
() -> {
126126
transportState.complete();
127-
asyncContext.complete();
127+
try {
128+
asyncContext.complete();
129+
} catch (IllegalStateException ignored) {
130+
// Tomcat can throw "Calling [asyncComplete()] is not valid for a request with Async state [COMPLETING]"
131+
}
128132
log.fine("call completed");
129133
});
130134
};
@@ -254,7 +258,7 @@ interface ActionItem {
254258
@VisibleForTesting // Lincheck test can not run with java.util.logging dependency.
255259
interface Log {
256260
default boolean isLoggable(Level level) {
257-
return false;
261+
return false;
258262
}
259263

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

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,11 @@ public void cancel(Status status) {
300300
close(Status.CANCELLED.withCause(status.asRuntimeException()), new Metadata());
301301
CountDownLatch countDownLatch = new CountDownLatch(1);
302302
transportState.runOnTransportThread(() -> {
303-
asyncCtx.complete();
303+
try {
304+
asyncCtx.complete();
305+
} catch (IllegalStateException ignored) {
306+
// Tomcat can throw "Calling [asyncComplete()] is not valid for a request with Async state [COMPLETING]"
307+
}
304308
countDownLatch.countDown();
305309
});
306310
try {

0 commit comments

Comments
 (0)