bugfix, outbound/failover: fail-timeout should cover the connect time

This commit is contained in:
eric
2023-05-24 04:09:24 +08:00
parent bd24848bc2
commit b4b7da5d14
2 changed files with 50 additions and 40 deletions

View File

@@ -120,29 +120,46 @@ impl OutboundDatagramHandler for Handler {
let a = &self.actors[i];
debug!(
"failover handles udp [{}] to [{}]",
"[{}] handles [{}:{}] to [{}]",
a.tag(),
sess.network,
sess.destination,
a.tag()
);
match timeout(
Duration::from_secs(self.fail_timeout as u64),
a.datagram()?.handle(
let try_outbound = async move {
a.datagram()?
.handle(
sess,
connect_datagram_outbound(sess, self.dns_client.clone(), a).await?,
),
)
.await
{
// return before timeout
};
match timeout(Duration::from_secs(self.fail_timeout as u64), try_outbound).await {
Ok(t) => match t {
// return ok
Ok(v) => return Ok(v),
// return err
Err(_) => continue,
Err(e) => {
trace!(
"[{}] failed to handle [{}:{}]: {}",
a.tag(),
sess.network,
sess.destination,
e,
);
continue;
}
},
// after timeout
Err(_) => continue,
Err(e) => {
trace!(
"[{}] failed to handle [{}:{}]: {}",
a.tag(),
sess.network,
sess.destination,
e,
);
continue;
}
}
}

View File

@@ -159,32 +159,23 @@ impl OutboundStreamHandler for Handler {
let a = &self.actors[actor_idx];
debug!(
"failover handles tcp [{}] to [{}]",
"[{}] handles [{}:{}] to [{}]",
a.tag(),
sess.network,
sess.destination,
a.tag()
);
match timeout(
Duration::from_secs(self.fail_timeout as u64),
a.stream()?.handle(
let try_outbound = async move {
a.stream()?
.handle(
sess,
match connect_stream_outbound(sess, self.dns_client.clone(), a).await {
Ok(v) => v,
Err(e) => {
trace!(
"[{}] failed to handle [{}]: {}",
a.tag(),
sess.destination,
e,
);
continue;
}
},
),
connect_stream_outbound(sess, self.dns_client.clone(), a).await?,
)
.await
{
// return before timeout
};
match timeout(Duration::from_secs(self.fail_timeout as u64), try_outbound).await {
Ok(t) => match t {
Ok(v) => {
// Only cache for fallback actors.
@@ -199,8 +190,9 @@ impl OutboundStreamHandler for Handler {
}
Err(e) => {
trace!(
"[{}] failed to handle [{}]: {}",
"[{}] failed to handle [{}:{}]: {}",
a.tag(),
sess.network,
sess.destination,
e,
);
@@ -209,8 +201,9 @@ impl OutboundStreamHandler for Handler {
},
Err(e) => {
trace!(
"[{}] failed to handle [{}]: {}",
"[{}] failed to handle [{}:{}]: {}",
a.tag(),
sess.network,
sess.destination,
e,
);