From 3c013ea89558e8e2bb4b2af3949c342188ebd485 Mon Sep 17 00:00:00 2001 From: Alex Rudy Date: Tue, 16 Apr 2024 02:47:31 +0000 Subject: [PATCH] Fix respons stream to only return a single error. According to [#689](https://github.com/hyperium/tonic/pull/689) streams should end after the first error. Therefore, when we find an error in the response step, discard the trailers so that the stream ends. --- tonic/src/codec/decode.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tonic/src/codec/decode.rs b/tonic/src/codec/decode.rs index 8cba8ba88..18412d733 100644 --- a/tonic/src/codec/decode.rs +++ b/tonic/src/codec/decode.rs @@ -285,6 +285,9 @@ impl StreamingInner { if let Direction::Response(status) = self.direction { if let Err(e) = crate::status::infer_grpc_status(self.trailers.as_ref(), status) { if let Some(e) = e { + // If the trailers contain a grpc-status, then we should return that as the error + // and otherwise stop the stream (by taking the error state) + self.trailers.take(); return Err(e); } }