From eec033f68b9b6845758638ebe09648e0981c0a1e Mon Sep 17 00:00:00 2001 From: Dmitrii Ubskii <18616863+dmitrii-ubskii@users.noreply.github.com> Date: Thu, 16 Nov 2023 13:42:15 +0300 Subject: [PATCH] Silence send errors in network callbacks when receiver dropped (#526) ## Release notes: usage and product changes Downgrade the "channel closed" `SendError` from ERROR to DEBUG when the receiving end of the stream is dropped before the stream is exhausted. --- rust/src/common/error.rs | 6 +++--- .../network/transmitter/response_sink.rs | 14 +++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/rust/src/common/error.rs b/rust/src/common/error.rs index 5d774416e5..6dbb86c2d8 100644 --- a/rust/src/common/error.rs +++ b/rust/src/common/error.rs @@ -79,7 +79,7 @@ error_messages! { InternalError RecvError() = 1: "Channel is closed.", SendError() = - 2: "Channel is closed.", + 2: "Unable to send response over callback channel (receiver dropped).", UnexpectedRequestType(String) = 3: "Unexpected request type for remote procedure call: {}.", UnexpectedResponseType(String) = @@ -215,8 +215,8 @@ impl From for Error { } impl From> for Error { - fn from(err: tokio::sync::mpsc::error::SendError) -> Self { - Self::Other(err.to_string()) + fn from(_err: tokio::sync::mpsc::error::SendError) -> Self { + Self::Internal(InternalError::SendError()) } } diff --git a/rust/src/connection/network/transmitter/response_sink.rs b/rust/src/connection/network/transmitter/response_sink.rs index 0d2ad5369d..5718a087cc 100644 --- a/rust/src/connection/network/transmitter/response_sink.rs +++ b/rust/src/connection/network/transmitter/response_sink.rs @@ -20,7 +20,7 @@ */ use crossbeam::channel::Sender as SyncSender; -use log::error; +use log::{debug, error}; use tokio::sync::{mpsc::UnboundedSender, oneshot::Sender as AsyncOneshotSender}; use crate::{ @@ -43,8 +43,10 @@ impl ResponseSink { Self::BlockingOneShot(sink) => sink.send(response).map_err(Error::from), Self::Streamed(sink) => sink.send(response).map_err(Error::from), }; - if let Err(err) = result { - error!("{}", err); + match result { + Err(Error::Internal(err @ InternalError::SendError())) => debug!("{err}"), + Err(err) => error!("{err}"), + Ok(()) => (), } } @@ -53,8 +55,10 @@ impl ResponseSink { Self::Streamed(sink) => sink.send(response).map_err(Error::from), _ => unreachable!("attempted to stream over a one-shot callback"), }; - if let Err(err) = result { - error!("{}", err); + match result { + Err(Error::Internal(err @ InternalError::SendError())) => debug!("{err}"), + Err(err) => error!("{err}"), + Ok(()) => (), } }