Skip to content

Client-side streaming early OK fails with StatusCode.CANCELLED from python client #992

Closed
@ebraraktas

Description

@ebraraktas

Bug Report

Version

└── tonic v0.7.1
└── tonic-build v0.7.1

Platform

Darwin Mustafas-MacBook-Pro.local 20.5.0 Darwin Kernel Version 20.5.0: Sat May 8 05:10:33 PDT 2021; root:xnu-7195.121.3~9/RELEASE_X86_64 x86_64

Description

I implemented simple client-side streaming endpoint using tonic-rs. It may return early if some condition occurs:

async fn record_route(
    &self,
    request: Request<Streaming<Point>>,
) -> Result<Response<RouteSummary>, Status> {
    let mut stream = request.into_inner();

    let mut summary = RouteSummary::default();

    while let Some(point) = stream.next().await {
        let point = point?;
        summary.point_count += 1;

        if point.latitude == 0 {
            println!("Return early: {}", summary.point_count);
            return Ok(Response::new(summary));
        }
    }
    println!("Return normal: {}", summary.point_count);
    Ok(Response::new(summary))
}

However, when I call this server from a simple python client it fails with the exception (StatusCode.CANCELLED) below:

# python client.py 5000
port = 5000
early_return_index = 2
Sleep 500 ms
Sleep 500 ms
Sleep 500 ms
Traceback (most recent call last):
  File "client.py", line 46, in <module>
    main()
  File "client.py", line 42, in main
    call_stream(client)
  File "client.py", line 34, in call_stream
    print(client.RecordRoute(iter_points()))
  File "/usr/local/lib/python3.8/site-packages/grpc/_channel.py", line 1131, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "/usr/local/lib/python3.8/site-packages/grpc/_channel.py", line 849, in _end_unary_response_blocking
    raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
        status = StatusCode.CANCELLED
        details = "Received RST_STREAM with error code 8"
        debug_error_string = "{"created":"@1651470233.217719000","description":"Error received from peer ipv6:[::1]:5000","file":"src/core/lib/surface/call.cc","file_line":1075,"grpc_message":"Received RST_STREAM with error code 8","grpc_status":1}"
>

GitHub repo to reproduce issue: https://github.com/ebraraktas/tonic-client-stream-early-ok

As the Issue section of README of the linked repo states, it runs ok with rust client. I know this may be related with grpc Python, but same server implemented in Python works smoothly if it is called from same Python client.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions