Don't hang in transaction_count (#1052)
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.
This commit is contained in:
@@ -189,14 +189,14 @@ impl ThinClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Request the transaction count. If the response packet is dropped by the network,
|
/// 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 {
|
pub fn transaction_count(&mut self) -> u64 {
|
||||||
debug!("transaction_count");
|
debug!("transaction_count");
|
||||||
let req = Request::GetTransactionCount;
|
let req = Request::GetTransactionCount;
|
||||||
let data =
|
let data =
|
||||||
serialize(&req).expect("serialize GetTransactionCount in pub fn transaction_count");
|
serialize(&req).expect("serialize GetTransactionCount in pub fn transaction_count");
|
||||||
let mut done = false;
|
let mut tries_left = 5;
|
||||||
while !done {
|
while tries_left > 0 {
|
||||||
self.requests_socket
|
self.requests_socket
|
||||||
.send_to(&data, &self.requests_addr)
|
.send_to(&data, &self.requests_addr)
|
||||||
.expect("buffer error in pub fn transaction_count");
|
.expect("buffer error in pub fn transaction_count");
|
||||||
@@ -204,9 +204,11 @@ impl ThinClient {
|
|||||||
if let Ok(resp) = self.recv_response() {
|
if let Ok(resp) = self.recv_response() {
|
||||||
debug!("transaction_count recv_response: {:?}", resp);
|
debug!("transaction_count recv_response: {:?}", resp);
|
||||||
if let Response::TransactionCount { .. } = resp {
|
if let Response::TransactionCount { .. } = resp {
|
||||||
done = true;
|
tries_left = 0;
|
||||||
}
|
}
|
||||||
self.process_response(&resp);
|
self.process_response(&resp);
|
||||||
|
} else {
|
||||||
|
tries_left -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.transaction_count
|
self.transaction_count
|
||||||
@@ -544,4 +546,18 @@ mod tests {
|
|||||||
server.join().unwrap();
|
server.join().unwrap();
|
||||||
remove_dir_all(ledger_path).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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user