Fix bug in force-unwrapping when resetting timers
When running tests locally, this error can surface.
```
---- test::agent_test::custom_resolver stdout ----
thread 'test::agent_test::custom_resolver' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 22, kind: InvalidInput, message: "Invalid argument" }', src/stream.rs:60:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```
The problem is that setting the timeouts might fail, and this is done
in a From trait where there is not possibility to "bubble" the
io::Error.
```
socket.set_read_timeout(None).unwrap();
socket.set_write_timeout(None).unwrap();
```
This commit moves the resetting of timers to an explicit `Stream::reset()` fn
that must be called every time we're unwrapping the inner stream.
This commit is contained in:
@@ -53,14 +53,7 @@ impl DeadlineStream {
|
||||
|
||||
impl From<DeadlineStream> for Stream {
|
||||
fn from(deadline_stream: DeadlineStream) -> Stream {
|
||||
// Since we are turning this back into a regular, non-deadline Stream,
|
||||
// remove any timeouts we set.
|
||||
let stream = deadline_stream.stream;
|
||||
if let Some(socket) = stream.socket() {
|
||||
socket.set_read_timeout(None).unwrap();
|
||||
socket.set_write_timeout(None).unwrap();
|
||||
}
|
||||
stream
|
||||
deadline_stream.stream
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,6 +152,17 @@ impl Stream {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn reset(&mut self) -> io::Result<()> {
|
||||
// When we are turning this back into a regular, non-deadline Stream,
|
||||
// remove any timeouts we set.
|
||||
if let Some(socket) = self.socket() {
|
||||
socket.set_read_timeout(None)?;
|
||||
socket.set_write_timeout(None)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn socket(&self) -> Option<&TcpStream> {
|
||||
match self {
|
||||
Stream::Http(b) => Some(b.get_ref()),
|
||||
|
||||
Reference in New Issue
Block a user