Hi there, Cancellation should really be considered an out-of-band unclean termination of the stream. There isn't even a library-level guarantee at that point of what has been seen or not seen, and a cancellation terminates both sides of the stream at the transport level so that the server can't even send trailing metadata on the wire (though you still have to give status for the RPC for library-level cleanup). So I'd really recommend not using it if you want a clean recovery. Instead, consider changing your application-layer protocol. For example, if you're using protobuf, you could change your message type to be a oneof between your existing message type and a new "CleanCancel" message so that way the Read will succeed and then you'll see that it was a CleanCancel message. If you're using the generic API as many proxies are likely to do, you could just instrument your proxy messages with an enum at the beginning to specify the type of message being sent and that would identify the cancellation. In other words, if you want a clean, graceful termination you need to do it via messages and not cancellation.
- vjpai On Friday, January 15, 2021 at 1:58:54 AM UTC-8 [email protected] wrote: > I'm trying to use server trailing metadata ( > https://chromium.googlesource.com/external/github.com/grpc/grpc/+/HEAD/examples/cpp/metadata > ). > > But the metadata doesn't seem to be propagated to the client unless the > return status is "OK" ? > > fredag 15 januari 2021 kl. 09:44:03 UTC+1 skrev [email protected]: > >> I'm writing a proxy which is put between a gRPC client and a server, >> which need to implement a bidirectional streaming RPC. >> >> Problem is that reading the client stream can only be cancelled with >> context->TryCancel(). And this will make the RPC return status CANCELLED >> (in the client) regardless of what actually is returned in the server RPC >> itself. >> >> Any idea on how to interrupt the stream->Read(...) call without >> TryCancel()? Is it possible to have a polled Read of the stream, so I can >> monitor and interrupt the RPC call? >> >> Regards >> /R >> >> -- You received this message because you are subscribed to the Google Groups "grpc.io" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/be7d3875-146f-4982-a833-74ab5b8f286fn%40googlegroups.com.
