From 9303e4dfddd660d1f59cb32eb36a6b4e16eb56f4 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Tue, 2 Dec 2014 20:47:34 -0800 Subject: [PATCH] Fix race condition in next_block_for If we hit the timeout while not blocked on read, the timeout would overflow. --- src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index f71b7e07..525d08e3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -73,7 +73,7 @@ use openssl::ssl::{SslContext, MaybeSslStream}; use serialize::hex::ToHex; use std::cell::{Cell, RefCell}; use std::collections::{RingBuf, HashMap}; -use std::io::{BufferedStream, IoResult, IoError, IoErrorKind}; +use std::io::{BufferedStream, IoResult, IoError, IoErrorKind, standard_error}; use std::io::net::ip::Port; use std::iter::IteratorCloneExt; use std::time::Duration; @@ -279,6 +279,9 @@ impl<'conn> Notifications<'conn> { let end = time::now().to_timespec() + timeout; loop { let now = time::now().to_timespec(); + if now > end { + return Err(Error::IoError(standard_error(IoErrorKind::TimedOut))); + } conn.stream.set_read_timeout(Some((end - now).num_milliseconds() as u64)); match conn.read_one_message() { Ok(Some(NotificationResponse { pid, channel, payload })) => {