Skip to content

[runtime/network] Allow read timeout recovery #2596

@clabby

Description

@clabby

Overview

Currently, if a read times out in the tokio Stream impl, the partially read data will be lost due to read_exact not being cancel safe. We currently disconnect upstream of this code if a timeout occurs, but if we want to support recovery, we'll need to consider holding read data in a buffer (or in an error variant) for recovery purposes.

impl crate::Stream for Stream {
async fn recv(&mut self, buf: impl Into<StableBuf> + Send) -> Result<StableBuf, Error> {
let mut buf = buf.into();
if buf.is_empty() {
return Ok(buf);
}
// Time out if we take too long to read
timeout(self.read_timeout, self.stream.read_exact(buf.as_mut()))
.await
.map_err(|_| Error::Timeout)?
.map_err(|_| Error::RecvFailed)?;
Ok(buf)
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    to-considerFurther consideration is needed whether this should be implemented

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions