Skip to content

servlet: Implement gRPC server as a Servlet #8596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 133 commits into from
Jan 20, 2023
Merged
Changes from 1 commit
Commits
Show all changes
133 commits
Select commit Hold shift + click to select a range
a0c92df
POC: Implement gRPC server as a Servlet
dapengzhang0 Jul 31, 2018
8719377
better-logging
dapengzhang0 Aug 12, 2018
46d00ec
get rid of public ServerImpl
dapengzhang0 Aug 13, 2018
4fa6271
rename files
dapengzhang0 Aug 14, 2018
e793c7c
fix serverListener NPE
dapengzhang0 Aug 14, 2018
393fcf6
fix onSendingBytes()
dapengzhang0 Aug 15, 2018
706a3c9
favor ConcurrentLinkedQueue for library
dapengzhang0 Aug 16, 2018
5e11674
refactor ServletAdapterImpl to ServletAdapter
dapengzhang0 Aug 17, 2018
1776917
not to use CDI for simplicity
dapengzhang0 Aug 17, 2018
bb3a720
add GrpcServlet(ServletServerBuilder serverBuilder)
dapengzhang0 Oct 15, 2018
4c7cd4f
add UndertowInteropTest and UndertowAbstractTest
dapengzhang0 Nov 2, 2018
af7f6a3
fix codecov
dapengzhang0 Nov 15, 2018
2fc04fc
minor enhancements
dapengzhang0 Nov 16, 2018
6fb4fc2
Merge branch 'master' of https://github.com/grpc/grpc-java into servl…
dapengzhang0 Jan 2, 2019
8b78b6d
update example gradle files
dapengzhang0 Jan 3, 2019
680872b
Merge branch 'master' of https://github.com/grpc/grpc-java into servl…
dapengzhang0 Jan 7, 2019
b3473df
Merge branch 'master' of https://github.com/grpc/grpc-java into servl…
dapengzhang0 Jun 13, 2019
3728866
revert core/src/test/java/io/grpc/internal/AbstractTransportTest.java
dapengzhang0 Jun 13, 2019
58fce63
ignore some transport tests
dapengzhang0 Jun 13, 2019
5b02064
cleanup GrpcServlet constructor
dapengzhang0 Jun 13, 2019
d59f81e
better way to get authority
dapengzhang0 Jun 13, 2019
5b7496e
comment SPSC
dapengzhang0 Jul 5, 2019
e98e4f8
attributes.toBuilder()
dapengzhang0 Jul 5, 2019
6aa26e4
move writeState and WriteListener
dapengzhang0 Jul 5, 2019
c3dfaba
Merge branch 'master' of https://github.com/grpc/grpc-java into servl…
dapengzhang0 Jul 8, 2019
44ea5f3
revert AbstractTransportTest reformat
dapengzhang0 Jul 8, 2019
ef5f879
temp
dapengzhang0 Jul 14, 2019
47e3e95
fix some of review comments
dapengzhang0 Jul 17, 2019
c5fc2bd
create util methods
dapengzhang0 Aug 7, 2019
63e8cb2
minor cleanup
dapengzhang0 Aug 7, 2019
986a885
Merge branch 'master' of https://github.com/grpc/grpc-java into servl…
dapengzhang0 Aug 11, 2019
3fd4ca8
factor out write path so that easy to replace with other implementation
dapengzhang0 Aug 12, 2019
09967c1
xds: gate xDS timeout with env variable (v1.33.x backport) (#7504) (#…
voidzcy Oct 13, 2020
7d8410f
Update README etc to reference 1.33.0
dapengzhang0 Oct 20, 2020
a53114b
Merge commit '38952b0b3' into servletasync
niloc132 Jan 14, 2021
ae0085f
Update servlet build to catch up to changes at around the 1.25 release
niloc132 Jan 14, 2021
9a02c82
Merge commit '2d592642a' into servletasync
niloc132 Jan 14, 2021
7977de6
Merge commit '04cf90a9a' into servletasync
niloc132 Jan 14, 2021
811fcbe
Update test to use the new conventions
niloc132 Jan 14, 2021
ccbfd8d
Merge commit 'df1b67869' into servletasync
niloc132 Jan 14, 2021
5d017a3
Merge commit '5c31dc6d7' into servletasync
niloc132 Jan 14, 2021
0180d29
Merge commit 'a86fc47c0' into servletasync
niloc132 Jan 15, 2021
7bb191c
Add explicit guava dependency
niloc132 Jan 15, 2021
59d9754
Merge commit '7047209ba' into servletasync
niloc132 Jan 15, 2021
1f4b0ca
Simple typos
niloc132 Sep 20, 2021
ccc5cd6
Merge commit 'v1.33.0^' into servletasync
niloc132 Sep 20, 2021
7d90af8
Merge commit '620d26667' into servletasync
niloc132 Sep 20, 2021
aea3351
Merge commit '73fe68eec' into servletasync
niloc132 Sep 20, 2021
70ca920
Merge commit '7d9ee8f05' into servletasync
niloc132 Sep 21, 2021
83d405e
Merge commit '828b03da2' into servletasync
niloc132 Sep 21, 2021
18d20d3
Merge commit 'd2160ea70' into servletasync
niloc132 Sep 21, 2021
f4c0c87
Merge commit 'dc74a31be' into servletasync
niloc132 Sep 21, 2021
b12370e
Merge commit '1e858921e' into servletasync
niloc132 Sep 21, 2021
a39be4c
tomcat
dapengzhang0 Aug 19, 2019
dea10c6
amend tomcat/jetty tests so they build after cherry-pick
niloc132 Sep 21, 2021
2154764
Relax jetty rate control
niloc132 Sep 23, 2021
bf5c225
Fix typo in log config, though apparently not used?
niloc132 Sep 23, 2021
a0b5852
Update tests to keep classpaths apart, fix/ignore failures
niloc132 Sep 27, 2021
512a2d3
Tomcat test cleanup, note about intermittent test
niloc132 Sep 27, 2021
4bed353
Typo in test class
niloc132 Sep 27, 2021
907f432
Restore another test setup piece, with fixed dependencies
niloc132 Sep 27, 2021
75f9b82
Update to java-library plugin, build javadoc
niloc132 Sep 27, 2021
cf3decb
Stubbed in servlet-jakarta project, rewrite commit with vers
niloc132 Sep 29, 2021
00b8f76
Simplify tests for javax.servlet
niloc132 Oct 12, 2021
35e0af2
Checkpoint before rewriting without this jakarta plugin...
niloc132 Oct 12, 2021
0c5664c
Working build+test on jakarta, with markers to delete jetty9 workaround
niloc132 Oct 13, 2021
8162d6e
Finish removing jakarta plugin
niloc132 Oct 13, 2021
8e25c4c
Merge remote-tracking branch 'upstream/master' into servletasync
niloc132 Oct 13, 2021
3bcd0af
Handle Java8 as well as Java11
niloc132 Oct 13, 2021
034771f
Disable another intermittent tomcat test
niloc132 Oct 13, 2021
da85cf8
Import cleanup
niloc132 Oct 13, 2021
f84a156
Upgrade various versions to latest, add some details about specific
niloc132 Oct 13, 2021
f7677f6
Example servlet readme
niloc132 Oct 13, 2021
dc2ddcf
Remove note that no longer applies
niloc132 Oct 13, 2021
cc9eb3f
Correct a different maven repo url
niloc132 Oct 13, 2021
67eb249
Rearrange test code, add jetty transport test
niloc132 Oct 26, 2021
c8eea3b
Update jakarta servlet tests too
niloc132 Oct 26, 2021
36c4e08
Merge remote-tracking branch 'upstream/master' into servletasync
niloc132 Oct 26, 2021
490abf2
Fix readme link error
niloc132 Oct 26, 2021
0db2bdf
Address JdkObsolete build errors
niloc132 Oct 26, 2021
6440b3b
Revert attempt to avoid StringBuffer, and add JdkObsolete suppress in…
niloc132 Nov 4, 2021
cc2297d
Fix build bug preventing jetty10 tests from running
niloc132 Nov 4, 2021
6197088
Merge branch 'master' into servlet-niloc132
dapengzhang0 Dec 22, 2021
9acba27
Make buildTransportServers() package private and VisibleForTesting
dapengzhang0 Dec 22, 2021
44fc657
fix bad import
dapengzhang0 Dec 22, 2021
6764b77
remove logging in test
dapengzhang0 Dec 22, 2021
7cce389
use org.apache.tomcat:annotations-api instead of javax.annotation
dapengzhang0 Dec 22, 2021
33639da
update RELEASING.md
dapengzhang0 Dec 22, 2021
822701e
remove unnecessary line
niloc132 Nov 29, 2021
f1a2ff3
Correctly publish jakarta artifact
niloc132 Dec 23, 2021
2a26e5e
Use empty() rather than making an empty byte[]
niloc132 Dec 23, 2021
a72bed1
Remove jetty 9 workaround
niloc132 Dec 23, 2021
a67519c
Update to latest servlet impls for tests
niloc132 Dec 23, 2021
0741d02
Configure tomcat to allow tests, remove skipped tests this fixes
niloc132 Dec 27, 2021
c88e1ce
retain test SourceSet for (future) normal unit test
dapengzhang0 Dec 29, 2021
4a55684
disable checkstyle in servlet-jakarta completely
dapengzhang0 Dec 29, 2021
d77973e
Revert "update RELEASING.md"
dapengzhang0 Dec 30, 2021
e632dde
make grpc-core an implementation dependency
dapengzhang0 Dec 30, 2021
c903d75
cleanup AsyncServletOutputStreamWriter
dapengzhang0 Dec 30, 2021
0bc4dcc
workaround tomcat outputStream.isReayd NPE after asyncCtx.complete
dapengzhang0 Jan 9, 2022
d73bad1
remove timeout rule for UndertowTransportTest
dapengzhang0 Jan 9, 2022
714e81b
Merge branch 'master' into servlet-niloc132
dapengzhang0 Jan 9, 2022
1962a0e
add jacoco coverage
dapengzhang0 Jan 9, 2022
022c66c
fix jacoco
dapengzhang0 Jan 9, 2022
bfef2a2
Change packages for jakarta servlet types
niloc132 Jan 19, 2022
bd3d791
Suppress java9+ warnings/errors from tomcat illegal reflective access
niloc132 Jan 19, 2022
533bd21
Merge branch 'master' into servlet-niloc132
dapengzhang0 Jan 22, 2022
6f7e626
bump grpc version in example
dapengzhang0 Jan 22, 2022
bc802ae
Un-ignore JettyInteropTest.gracefulShutdown
dapengzhang0 Jan 22, 2022
b1da336
Add servlet to grpc-all:javadoc
dapengzhang0 Jan 27, 2022
93f1c6f
fix jakarta build warning
dapengzhang0 Jan 27, 2022
0e64316
Concurrency correctness test for AsyncServletOutputStreamWriter
dapengzhang0 Jan 27, 2022
38c0585
enhance lincheck test
dapengzhang0 Feb 8, 2022
5cb764a
add test for builder scheduler and GrpcServlet constructor
dapengzhang0 Feb 16, 2022
986ee81
add test for builder scheduler and GrpcServlet constructor 2
dapengzhang0 Feb 16, 2022
95c350f
ignore flaky undertow test
dapengzhang0 Feb 16, 2022
7a90a53
add Test annotation
dapengzhang0 Feb 16, 2022
f8b9950
improve builder test
dapengzhang0 Feb 16, 2022
576d64e
response with error code for GET method
dapengzhang0 Feb 18, 2022
50020b3
fix executorPool and TIMER_SERVICE leak after servlet.destroy()
dapengzhang0 Feb 27, 2022
79dc180
Merge branch 'master' into servlet-niloc132
dapengzhang0 Mar 9, 2022
6d58c9b
bump grpc version in example
dapengzhang0 Mar 9, 2022
dda244d
Merge commit '78ccc81fd' into servletasync
niloc132 May 10, 2022
5829381
Merge branch 'master' of https://github.com/grpc/grpc-java into servl…
dapengzhang0 Jun 22, 2022
7ae71dc
bump grpc version in example
dapengzhang0 Jun 22, 2022
639084a
Use Gradle's version catalog
dapengzhang0 Jun 22, 2022
b13d505
regression while bumping to v1.47.0
dapengzhang0 Jun 22, 2022
5bbaea3
Merge commit '7bdca0c0e' into servletasync
niloc132 Jan 20, 2023
524bbe9
Merge commit 'e998955d1' into servletasync
niloc132 Jan 20, 2023
129628e
Merge commit 'a82ea0cb0' into servletasync
niloc132 Jan 20, 2023
4c68cfb
Merge commit 'e325dc911' into servletasync
niloc132 Jan 20, 2023
f26201a
Merge remote-tracking branch 'upstream/master' into servletasync
niloc132 Jan 20, 2023
7929461
Review feedback, version bump
niloc132 Jan 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
minor cleanup
  • Loading branch information
dapengzhang0 committed Aug 7, 2019
commit 63e8cb2ff9987ead928f7d5551b63543c3cda9ba
35 changes: 13 additions & 22 deletions servlet/src/main/java/io/grpc/servlet/ServletServerStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.servlet.AsyncContext;
import javax.servlet.ServletOutputStream;
import javax.servlet.WriteListener;
import javax.servlet.http.HttpServletResponse;

Expand All @@ -64,7 +63,7 @@ final class ServletServerStream extends AbstractServerStream {
private static final Logger logger = Logger.getLogger(ServletServerStream.class.getName());

private final ServletTransportState transportState;
private final Sink sink;
private final Sink sink = new Sink();
private final AsyncContext asyncCtx;
private final HttpServletResponse resp;
private final AtomicReference<WriteState> writeState = new AtomicReference<>(WriteState.DEFAULT);
Expand All @@ -84,14 +83,12 @@ final class ServletServerStream extends AbstractServerStream {
super(ByteArrayWritableBuffer::new, statsTraceCtx);
transportState =
new ServletTransportState(maxInboundMessageSize, statsTraceCtx, new TransportTracer());
this.asyncCtx = asyncCtx;
this.resp = (HttpServletResponse) asyncCtx.getResponse();
this.attributes = attributes;
this.authority = authority;
this.logId = logId;
sink = new Sink();
asyncCtx.getResponse().getOutputStream()
.setWriteListener(new GrpcWriteListener());
this.asyncCtx = asyncCtx;
this.resp = (HttpServletResponse) asyncCtx.getResponse();
resp.getOutputStream().setWriteListener(new GrpcWriteListener());
}

@Override
Expand Down Expand Up @@ -162,7 +159,7 @@ private void callComplete() {
logger.log(FINE, "[{0}] call is completing", logId);
transportState.runOnTransportThread(
() -> {
transportState().complete();
transportState.complete();
asyncCtx.complete();
logger.log(FINE, "[{0}] call completed", logId);
});
Expand Down Expand Up @@ -279,11 +276,6 @@ WriteState newState() {
}

private final class GrpcWriteListener implements WriteListener {
final ServletOutputStream output;

GrpcWriteListener() throws IOException {
output = resp.getOutputStream();
}

@Override
public void onError(Throwable t) {
Expand All @@ -293,11 +285,11 @@ public void onError(Throwable t) {

// If the resp is not committed, cancel() to avoid being redirected to an error page.
// Else, the container will send RST_STREAM at the end.
if (!asyncCtx.getResponse().isCommitted()) {
if (!resp.isCommitted()) {
cancel(Status.fromThrowable(t));
} else {
transportState().runOnTransportThread(
() -> transportState().transportReportStatus(Status.fromThrowable(t)));
transportState.runOnTransportThread(
() -> transportState.transportReportStatus(Status.fromThrowable(t)));
}
}

Expand All @@ -312,7 +304,7 @@ public void onWritePossible() throws IOException {
}

boolean isReady;
while ((isReady = output.isReady())) {
while ((isReady = resp.getOutputStream().isReady())) {
WriteState curState = writeState.get();

ByteArrayWritableBuffer buffer = writeChain.poll();
Expand Down Expand Up @@ -443,21 +435,20 @@ public void writeTrailers(Metadata trailers, boolean headersSent, Status status)

@Override
public void request(int numMessages) {
transportState().runOnTransportThread(
() -> transportState().requestMessagesFromDeframer(numMessages));
transportState.runOnTransportThread(
() -> transportState.requestMessagesFromDeframer(numMessages));
}

@Override
public void cancel(Status status) {
if (resp.isCommitted() && Code.DEADLINE_EXCEEDED == status.getCode()) {
return; // let the servlet timeout, the container will sent RST_STREAM automatically
}
transportState().runOnTransportThread(
() -> transportState().transportReportStatus(status));
transportState.runOnTransportThread(() -> transportState.transportReportStatus(status));
// There is no way to RST_STREAM with CANCEL code, so write trailers instead
close(Status.CANCELLED.withCause(status.asRuntimeException()), new Metadata());
CountDownLatch countDownLatch = new CountDownLatch(1);
transportState().runOnTransportThread(() -> {
transportState.runOnTransportThread(() -> {
asyncCtx.complete();
countDownLatch.countDown();
});
Expand Down