diff options
-rw-r--r-- | src/endpoint.rs | 5 | ||||
-rw-r--r-- | src/message.rs | 4 |
2 files changed, 8 insertions, 1 deletions
diff --git a/src/endpoint.rs b/src/endpoint.rs index 31500aa..588f7e3 100644 --- a/src/endpoint.rs +++ b/src/endpoint.rs @@ -52,7 +52,10 @@ where T: EndpointHandler<M>, M: Message + 'static, { - async fn handle(self: &Arc<Self>, m: Req<M>, from: NodeID) -> Resp<M> { + async fn handle(self: &Arc<Self>, mut m: Req<M>, from: NodeID) -> Resp<M> { + // Immediately drop stream to avoid backpressure if a stream was sent + // (this will make all data sent to the stream be ignored immediately) + drop(m.take_stream()); Resp::new(EndpointHandler::handle(self, m.msg(), from).await) } } diff --git a/src/message.rs b/src/message.rs index ba06551..0ac4cb8 100644 --- a/src/message.rs +++ b/src/message.rs @@ -81,6 +81,10 @@ impl<M: Message> Req<M> { } } + pub fn take_stream(&mut self) -> Option<ByteStream> { + std::mem::replace(&mut self.body, BodyData::None).into_stream() + } + pub(crate) fn into_enc( self, prio: RequestPriority, |