Skip to content

Commit 67c7744

Browse files
authored
Make FailFast cloneable (#617)
Currently, the FailFast middleware is not cloneable, as it maintains state including a timeout future. This change modifies FailFast to implement Clone. When the module is cloned, it reverts to the open state. This has no impact on the current proxy, but when the stack gets cloned (as required by an upcoming change), this will have the effect that connections do not share failfast state. This seems better than adding a Lock or Buffer just to accomodate this.
1 parent 22e82e8 commit 67c7744

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

linkerd/timeout/src/failfast.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,23 @@ impl<S> tower::layer::Layer<S> for FailFastLayer {
6060

6161
// === impl FailFast ===
6262

63+
impl<S> Clone for FailFast<S>
64+
where
65+
S: Clone,
66+
{
67+
fn clone(&self) -> Self {
68+
// When cloning failfast, we can't preserve the waiting state, so each
69+
// clone will have to detect its own failfast. Practically, this means
70+
// that each connection will have to wait for a timeout before
71+
// triggering failfast.
72+
Self {
73+
inner: self.inner.clone(),
74+
max_unavailable: self.max_unavailable.clone(),
75+
state: State::Open,
76+
}
77+
}
78+
}
79+
6380
impl<S, T> tower::Service<T> for FailFast<S>
6481
where
6582
S: tower::Service<T>,

0 commit comments

Comments
 (0)