channelz: ServerData `calls_failed` counter not incremented upon client cancellation

Open Beginner friendly
#13,063 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java
Domain
observability

Research direction

Start with ServerCallImplTest.java and the callTracer_clientCancelled_reportsCallFailed test, then trace ServerStreamListenerImpl.closed(Status.CANCELLED) through the serverCallTracer updates. The change is done when a client-cancelled call leaves callsStarted at 1, callsSucceeded at 0, and callsFailed at 1 in the test.

Written by the indexing model from the issue text.

Description

enhancement
What version of gRPC are you using?

HEAD

What did you expect to see?

Per grpc/channelz/v1/channelz.proto (ServerData):


// ServerData is data for a specific Server.
message ServerData {
  ...
  // The number of incoming calls started on the server
  int64 calls_started = 2;
  // The number of incoming calls that have completed with an OK status
  int64 calls_succeeded = 3;
  // The number of incoming calls that have a completed with a non-OK status
  int64 calls_failed = 4;
  ...

When an incoming RPC terminates due to client cancellation, transport reset, or client-side deadline expiration, the call terminates with non-OK status (Status.CANCELLED). I expect this situation to be reflected in calls_failed.

What did you see instead?

calls_started increments when the call arrives at the server. However, when a call is cancelled by the client before the server application closes, neither calls_succeeded nor calls_failed is incremented.

Client cancellations or timeouts are not unusual. So on any long-lived server, calls_started - calls_succeeded - calls_failed grows larger and larger over time.

Steps to reproduce

For ServerCallImplTest.java

  @Test
  public void callTracer_clientCancelled_reportsCallFailed() {
    ServerStreamListenerImpl<Long> streamListener =
        new ServerCallImpl.ServerStreamListenerImpl<>(call, callListener, context);

    streamListener.closed(Status.CANCELLED);

    ServerStats.Builder afterBuilder = new ServerStats.Builder();
    serverCallTracer.updateBuilder(afterBuilder);
    ServerStats after = afterBuilder.build();
    assertEquals(1, after.callsStarted);
    assertEquals(0, after.callsSucceeded);
    assertEquals(1, after.callsFailed); // <--- Fails. Actual value is 0.
  }
Dominant language
Java
Stars
12.1k
Forks
4k
Avg merge
2d 8h
Merged PRs (30d)
32

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from grpc/grpc-java

All issues in grpc/grpc-java

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.