core: always call StreamTracer.streamClosed() when stream is officially closed. (#4331)

Previously StreamTracer.streamClosed() is called in
ServerStream.close(), but it is not exactly when the stream is
officially closed.  ServerStreamListener.closed() is guaranteed to be
called and it is the official end of the stream.
This commit is contained in:
Kun Zhang 2018-04-12 09:05:48 -07:00 committed by GitHub
parent 7c46bd9399
commit 3f63cd0ad4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

View File

@ -128,7 +128,6 @@ public abstract class AbstractServerStream extends AbstractStream
Preconditions.checkNotNull(trailers, "trailers");
if (!outboundClosed) {
outboundClosed = true;
statsTraceCtx.streamClosed(status);
endOfMessages();
addStatusToTrailers(trailers, status);
// Safe to set without synchronization because access is tightly controlled.
@ -336,6 +335,7 @@ public abstract class AbstractServerStream extends AbstractStream
statsTraceCtx.streamClosed(newStatus);
getTransportTracer().reportStreamClosed(false);
} else {
statsTraceCtx.streamClosed(closedStatus);
getTransportTracer().reportStreamClosed(closedStatus.isOk());
}
listenerClosed = true;

View File

@ -776,10 +776,10 @@ public abstract class AbstractTransportTest {
trailers.put(asciiKey, "dupvalue");
trailers.put(binaryKey, "äbinarytrailers");
serverStream.close(status, trailers);
assertSame(status, serverStreamTracer1.getStatus());
assertNull(serverStreamTracer1.nextInboundEvent());
assertNull(serverStreamTracer1.nextOutboundEvent());
assertCodeEquals(Status.OK, serverStreamListener.status.get(TIMEOUT_MS, TimeUnit.MILLISECONDS));
assertSame(status, serverStreamTracer1.getStatus());
Status clientStreamStatus = clientStreamListener.status.get(TIMEOUT_MS, TimeUnit.MILLISECONDS);
Metadata clientStreamTrailers =
clientStreamListener.trailers.get(TIMEOUT_MS, TimeUnit.MILLISECONDS);