Skip to content

Commit 74988b8

Browse files
authored
Merge branch 'develop' into fix/deadlock
2 parents 8185911 + 3a48b09 commit 74988b8

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

testnet/stacks-node/src/event_dispatcher.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use std::thread::sleep;
66
use std::time::Duration;
77

88
use async_h1::client;
9+
use async_std::future::timeout;
910
use async_std::net::TcpStream;
11+
use async_std::task;
1012
use clarity::vm::analysis::contract_interface_builder::build_contract_interface;
1113
use clarity::vm::costs::ExecutionCost;
1214
use clarity::vm::events::{FTEventType, NFTEventType, STXEventType};
@@ -318,27 +320,33 @@ impl EventObserver {
318320
};
319321

320322
let backoff = Duration::from_millis((1.0 * 1_000.0) as u64);
323+
let connection_timeout = Duration::from_secs(5);
321324

322325
loop {
323326
let body = body.clone();
324327
let mut req = Request::new(Method::Post, url.clone());
325328
req.append_header("Content-Type", "application/json");
326329
req.set_body(body);
327330

328-
let response = async_std::task::block_on(async {
329-
let stream = match TcpStream::connect(self.endpoint.clone()).await {
330-
Ok(stream) => stream,
331-
Err(err) => {
332-
warn!("Event dispatcher: connection failed - {:?}", err);
333-
return None;
334-
}
335-
};
331+
let response = task::block_on(async {
332+
let stream =
333+
match timeout(connection_timeout, TcpStream::connect(&self.endpoint)).await {
334+
Ok(Ok(stream)) => stream,
335+
Ok(Err(err)) => {
336+
warn!("Event dispatcher: connection failed - {:?}", err);
337+
return None;
338+
}
339+
Err(_) => {
340+
error!("Event dispatcher: connection attempt timed out");
341+
return None;
342+
}
343+
};
336344

337345
match client::connect(stream, req).await {
338346
Ok(response) => Some(response),
339347
Err(err) => {
340348
warn!("Event dispatcher: rpc invocation failed - {:?}", err);
341-
return None;
349+
None
342350
}
343351
}
344352
});

0 commit comments

Comments
 (0)