Skip to content

Commit 19076c1

Browse files
committed
chore: only timout on the TcpStream::connect
Don't timeout on the `client::connect` since this has the potential for an observer to receive duplicate events.
1 parent 522dcf2 commit 19076c1

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

testnet/stacks-node/src/event_dispatcher.rs

Lines changed: 19 additions & 19 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};
@@ -326,26 +328,24 @@ impl EventObserver {
326328
req.append_header("Content-Type", "application/json");
327329
req.set_body(body);
328330

329-
let response = async_std::task::block_on(async {
330-
match async_std::future::timeout(
331-
connection_timeout,
332-
TcpStream::connect(self.endpoint.clone()),
333-
)
334-
.await
335-
{
336-
Ok(Ok(stream)) => match client::connect(stream, req).await {
337-
Ok(response) => Some(response),
338-
Err(err) => {
339-
warn!("Event dispatcher: rpc invocation failed - {:?}", err);
340-
None
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;
341338
}
342-
},
343-
Ok(Err(err)) => {
344-
warn!("Event dispatcher: connection failed - {:?}", err);
345-
None
346-
}
347-
Err(_) => {
348-
error!("Event dispatcher: connection attempt timed out");
339+
Err(_) => {
340+
error!("Event dispatcher: connection attempt timed out");
341+
return None;
342+
}
343+
};
344+
345+
match client::connect(stream, req).await {
346+
Ok(response) => Some(response),
347+
Err(err) => {
348+
warn!("Event dispatcher: rpc invocation failed - {:?}", err);
349349
None
350350
}
351351
}

0 commit comments

Comments
 (0)