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

Partially revert "core: change serverimpl,servercallimpl's internalcl… #4168

Merged
merged 1 commit into from
Mar 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion core/src/main/java/io/grpc/internal/ServerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,8 @@ void setListener(ServerStreamListener listener) {
* Like {@link ServerCall#close(Status, Metadata)}, but thread-safe for internal use.
*/
private void internalClose() {
stream.cancel(Status.INTERNAL);
// TODO(ejona86): this is not thread-safe :)
stream.close(Status.UNKNOWN, new Metadata());
}

@Override
Expand Down
19 changes: 10 additions & 9 deletions core/src/test/java/io/grpc/internal/ServerImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ public void messageRead_errorCancelsCall() throws Exception {
fail("Expected exception");
} catch (TestError t) {
assertSame(expectedT, t);
ensureServerStateIsCancelled();
ensureServerStateNotLeaked();
}
}

Expand All @@ -1135,7 +1135,7 @@ public void messageRead_runtimeExceptionCancelsCall() throws Exception {
fail("Expected exception");
} catch (RuntimeException t) {
assertSame(expectedT, t);
ensureServerStateIsCancelled();
ensureServerStateNotLeaked();
}
}

Expand All @@ -1158,7 +1158,7 @@ public void halfClosed_errorCancelsCall() {
fail("Expected exception");
} catch (TestError t) {
assertSame(expectedT, t);
ensureServerStateIsCancelled();
ensureServerStateNotLeaked();
}
}

Expand All @@ -1181,7 +1181,7 @@ public void halfClosed_runtimeExceptionCancelsCall() {
fail("Expected exception");
} catch (RuntimeException t) {
assertSame(expectedT, t);
ensureServerStateIsCancelled();
ensureServerStateNotLeaked();
}
}

Expand All @@ -1204,7 +1204,7 @@ public void onReady_errorCancelsCall() {
fail("Expected exception");
} catch (TestError t) {
assertSame(expectedT, t);
ensureServerStateIsCancelled();
ensureServerStateNotLeaked();
}
}

Expand All @@ -1227,7 +1227,7 @@ public void onReady_runtimeExceptionCancelsCall() {
fail("Expected exception");
} catch (RuntimeException t) {
assertSame(expectedT, t);
ensureServerStateIsCancelled();
ensureServerStateNotLeaked();
}
}

Expand Down Expand Up @@ -1430,10 +1430,11 @@ private void verifyExecutorsReturned() {
verifyNoMoreInteractions(executorPool);
}

private void ensureServerStateIsCancelled() {
verify(stream).cancel(statusCaptor.capture());
assertEquals(Status.INTERNAL, statusCaptor.getValue());
private void ensureServerStateNotLeaked() {
verify(stream).close(statusCaptor.capture(), metadataCaptor.capture());
assertEquals(Status.UNKNOWN, statusCaptor.getValue());
assertNull(statusCaptor.getValue().getCause());
assertTrue(metadataCaptor.getValue().keys().isEmpty());
}

private static class SimpleServer implements io.grpc.internal.InternalServer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public void onCompleted() {
.onNext(StreamingInputCallRequest.getDefaultInstance());

assertTrue(finishLatch.await(900, TimeUnit.MILLISECONDS));
assertEquals(Status.CANCELLED.getCode(), Status.fromThrowable(throwableRef.get()).getCode());
assertEquals(Status.UNKNOWN, Status.fromThrowable(throwableRef.get()));
assertNull(responseRef.get());
}
}
7 changes: 1 addition & 6 deletions netty/src/main/java/io/grpc/netty/NettyServerHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -651,13 +651,8 @@ private void cancelStream(ChannelHandlerContext ctx, CancelServerStreamCommand c
ChannelPromise promise) {
// Notify the listener if we haven't already.
cmd.stream().transportReportStatus(cmd.reason());
Http2Error http2Error = Http2Error.INTERNAL_ERROR;
if (Status.DEADLINE_EXCEEDED.getCode().equals(cmd.reason().getCode()) || Status.CANCELLED
.getCode().equals(cmd.reason().getCode())) {
http2Error = Http2Error.CANCEL;
}
// Terminate the stream.
encoder().writeRstStream(ctx, cmd.stream().id(), http2Error.code(), promise);
encoder().writeRstStream(ctx, cmd.stream().id(), Http2Error.CANCEL.code(), promise);
}

private void forcefulClose(final ChannelHandlerContext ctx, final ForcefulCloseCommand msg,
Expand Down