Skip to content

Commit 9303e4d

Browse files
committed
Fix race condition in next_block_for
If we hit the timeout while not blocked on read, the timeout would overflow.
1 parent d5998d8 commit 9303e4d

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ use openssl::ssl::{SslContext, MaybeSslStream};
7373
use serialize::hex::ToHex;
7474
use std::cell::{Cell, RefCell};
7575
use std::collections::{RingBuf, HashMap};
76-
use std::io::{BufferedStream, IoResult, IoError, IoErrorKind};
76+
use std::io::{BufferedStream, IoResult, IoError, IoErrorKind, standard_error};
7777
use std::io::net::ip::Port;
7878
use std::iter::IteratorCloneExt;
7979
use std::time::Duration;
@@ -279,6 +279,9 @@ impl<'conn> Notifications<'conn> {
279279
let end = time::now().to_timespec() + timeout;
280280
loop {
281281
let now = time::now().to_timespec();
282+
if now > end {
283+
return Err(Error::IoError(standard_error(IoErrorKind::TimedOut)));
284+
}
282285
conn.stream.set_read_timeout(Some((end - now).num_milliseconds() as u64));
283286
match conn.read_one_message() {
284287
Ok(Some(NotificationResponse { pid, channel, payload })) => {

0 commit comments

Comments
 (0)