Skip to content

Commit

Permalink
Don't hang in transaction_count (#1052)
Browse files Browse the repository at this point in the history
Situation is there can be that there can be bad entries in
the bench-tps CRDT table until they get purged later. Threads however
are created for those bad entries and then will hang on trying
to get the transaction_count from those bad addresses and never end.
  • Loading branch information
sakridge authored Aug 24, 2018
1 parent 7131997 commit 6fc21a4
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/thin_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,24 +189,26 @@ impl ThinClient {
}

/// Request the transaction count. If the response packet is dropped by the network,
/// this method will hang.
/// this method will try again 5 times.
pub fn transaction_count(&mut self) -> u64 {
debug!("transaction_count");
let req = Request::GetTransactionCount;
let data =
serialize(&req).expect("serialize GetTransactionCount in pub fn transaction_count");
let mut done = false;
while !done {
let mut tries_left = 5;
while tries_left > 0 {
self.requests_socket
.send_to(&data, &self.requests_addr)
.expect("buffer error in pub fn transaction_count");

if let Ok(resp) = self.recv_response() {
debug!("transaction_count recv_response: {:?}", resp);
if let Response::TransactionCount { .. } = resp {
done = true;
tries_left = 0;
}
self.process_response(&resp);
} else {
tries_left -= 1;
}
}
self.transaction_count
Expand Down Expand Up @@ -544,4 +546,18 @@ mod tests {
server.join().unwrap();
remove_dir_all(ledger_path).unwrap();
}

#[test]
fn test_transaction_count() {
// set a bogus address, see that we don't hang
logger::setup();
let addr = "0.0.0.0:1234".parse().unwrap();
let requests_socket = UdpSocket::bind("0.0.0.0:0").unwrap();
requests_socket
.set_read_timeout(Some(Duration::from_millis(250)))
.unwrap();
let transactions_socket = UdpSocket::bind("0.0.0.0:0").unwrap();
let mut client = ThinClient::new(addr, requests_socket, addr, transactions_socket);
assert_eq!(client.transaction_count(), 0);
}
}

0 comments on commit 6fc21a4

Please sign in to comment.