Skip to content

Commit

Permalink
census: fix NPE in calling recordFinishedAttempt()
Browse files Browse the repository at this point in the history
  • Loading branch information
dapengzhang0 committed Nov 15, 2021
1 parent b746bab commit 32fdeef
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions census/src/main/java/io/grpc/census/CensusStatsModule.java
Expand Up @@ -342,9 +342,6 @@ public void outboundMessage(int seqNo) {

@Override
public void streamClosed(Status status) {
attemptsState.attemptEnded();
stopwatch.stop();
roundtripNanos = stopwatch.elapsed(TimeUnit.NANOSECONDS);
Deadline deadline = info.getCallOptions().getDeadline();
statusCode = status.getCode();
if (statusCode == Status.Code.CANCELLED && deadline != null) {
Expand All @@ -355,6 +352,9 @@ public void streamClosed(Status status) {
statusCode = Code.DEADLINE_EXCEEDED;
}
}
attemptsState.attemptEnded();
stopwatch.stop();
roundtripNanos = stopwatch.elapsed(TimeUnit.NANOSECONDS);
if (inboundReceivedOrClosed.compareAndSet(false, true)) {
if (module.recordFinishedRpcs) {
// Stream is closed early. So no need to record metrics for any inbound events after this
Expand Down Expand Up @@ -522,6 +522,8 @@ void recordFinishedCall() {
tracer.statusCode = status.getCode();
tracer.recordFinishedAttempt();
} else if (inboundMetricTracer != null) {
// activeStreams has been decremented to 0 by attemptEnded(),
// so inboundMetricTracer.statusCode is guaranteed to be assigned already.
inboundMetricTracer.recordFinishedAttempt();
}
if (!module.recordRetryMetrics) {
Expand Down

0 comments on commit 32fdeef

Please sign in to comment.