Skip to content

Commit 522dcf2

Browse files
committed
feat: timout connections to observers
Without a timout for these connections, the node can get stuck here and it is not obvious what is happening. With this timeout, we will see log messages that will point to the problem.
1 parent f49e69a commit 522dcf2

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

testnet/stacks-node/src/event_dispatcher.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ impl EventObserver {
318318
};
319319

320320
let backoff = Duration::from_millis((1.0 * 1_000.0) as u64);
321+
let connection_timeout = Duration::from_secs(5);
321322

322323
loop {
323324
let body = body.clone();
@@ -326,19 +327,26 @@ impl EventObserver {
326327
req.set_body(body);
327328

328329
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) => {
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
341+
}
342+
},
343+
Ok(Err(err)) => {
332344
warn!("Event dispatcher: connection failed - {:?}", err);
333-
return None;
345+
None
334346
}
335-
};
336-
337-
match client::connect(stream, req).await {
338-
Ok(response) => Some(response),
339-
Err(err) => {
340-
warn!("Event dispatcher: rpc invocation failed - {:?}", err);
341-
return None;
347+
Err(_) => {
348+
error!("Event dispatcher: connection attempt timed out");
349+
None
342350
}
343351
}
344352
});

0 commit comments

Comments
 (0)