Skip to content
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

netty: improve server handling of writes to reset streams #10258

Merged
merged 4 commits into from
Feb 16, 2024
Merged
Changes from 1 commit
Commits
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
34 changes: 15 additions & 19 deletions netty/src/main/java/io/grpc/netty/NettyServerHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -677,14 +677,14 @@
}
}

private void closeStreamWhenDone(ChannelPromise promise, int streamId) throws Http2Exception {
final NettyServerStream.TransportState stream = serverStream(requireHttp2Stream(streamId));
promise.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) {
stream.complete();
}
});
private void closeStreamWhenDone(ChannelPromise promise, Http2Stream stream) {
promise.addListener(
new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) {
serverStream(stream).complete();
}
});
}

/**
Expand All @@ -695,11 +695,13 @@
try (TaskCloseable ignore = PerfMark.traceTask("NettyServerHandler.sendGrpcFrame")) {
PerfMark.attachTag(cmd.stream().tag());
PerfMark.linkIn(cmd.getLink());
if (cmd.endStream()) {
closeStreamWhenDone(promise, cmd.stream().id());
int streamId = cmd.stream().id();
Http2Stream stream = connection().stream(streamId);
if (stream != null && cmd.endStream()) {
closeStreamWhenDone(promise, stream);

Check warning on line 701 in netty/src/main/java/io/grpc/netty/NettyServerHandler.java

View check run for this annotation

Codecov / codecov/patch

netty/src/main/java/io/grpc/netty/NettyServerHandler.java#L701

Added line #L701 was not covered by tests
}
// Call the base class to write the HTTP/2 DATA frame.
encoder().writeData(ctx, cmd.stream().id(), cmd.content(), 0, cmd.endStream(), promise);
encoder().writeData(ctx, streamId, cmd.content(), 0, cmd.endStream(), promise);
}
}

Expand All @@ -711,16 +713,10 @@
try (TaskCloseable ignore = PerfMark.traceTask("NettyServerHandler.sendResponseHeaders")) {
PerfMark.attachTag(cmd.stream().tag());
PerfMark.linkIn(cmd.getLink());
// TODO(carl-mastrangelo): remove this check once https://github.com/netty/netty/issues/6296
// is fixed.
int streamId = cmd.stream().id();
Http2Stream stream = connection().stream(streamId);
if (stream == null) {
resetStream(ctx, streamId, Http2Error.CANCEL.code(), promise);
ejona86 marked this conversation as resolved.
Show resolved Hide resolved
return;
}
if (cmd.endOfStream()) {
closeStreamWhenDone(promise, streamId);
if (stream != null && cmd.endOfStream()) {
closeStreamWhenDone(promise, stream);
}
encoder().writeHeaders(ctx, streamId, cmd.headers(), 0, cmd.endOfStream(), promise);
}
Expand Down