Commit b28453f
fix(app/core): do not immediately retry negative ttl errors (#4450)
`linkerd_app_core::control` provides utilities used by the data plane to
communicate with the linkerd control plane. this includes, among other
features such as load-balancing and configurability for settings like
connection timeout durations, an error recovery that respects DNS
record's negative TTL.
as of today, we do this within an inline, anonymous closure.
this commit pulls this business logic out of an inline closure, and into
an explicit pair of structures.
ResolveRecover is the Recover implementation that handles identifying
the proper backoff strategy, when presented with a given boxed error.
ResolveBackoff is the structure that acts as the sum type that
encompasses either a TTL-driven interval, or an exponential backoff.
see also, #4449. that introduces some additional
guardrails to prevent panicking if a negative ttl of zero is
encountered.
as part of this code motion, this commit inserts a call to
`tokio::time::Interval::reset()` to the `Recover` implementation that
extracts negative TTL's from `hickory_resolver` errors.
this means that, upon resolution errors with a negative TTL, we will no
longer immediately retry, and instead wait for the prescribed time
before attempting once more.
introducing test coverage for this is difficult because we cannot create
a `ResolveError` ourselves, and introducing e.g. a trait to inject here
would incur an excessive amount of boilerplate and complexity.
to provide assurance that this is correct, see this small playground
example, in which we poll an `Interval` with and without this call to
`reset()`. note that when calling reset, it will no longer immediately
return `Poll::Ready(_)` upon the first call to `tick()`.
```rust
#[tokio::main]
async fn main() {
let duration = std::time::Duration::from_secs(1);
let mut interval = tokio::time::interval(duration);
// interval.reset();
let start = std::time::Instant::now();
for i in 1..5 {
interval.tick().await;
let elapsed = start.elapsed().as_millis();
println!("#{i} - {elapsed}ms")
}
}
```
```
; cargo run
#1 - 1ms
#2 - 1001ms
#3 - 2001ms
#4 - 3001ms
```
with a reset, to avoid first poll being ready:
```rust
#[tokio::main]
async fn main() {
let duration = std::time::Duration::from_secs(1);
let mut interval = tokio::time::interval(duration);
interval.reset();
let start = std::time::Instant::now();
for i in 1..5 {
interval.tick().await;
let elapsed = start.elapsed().as_millis();
println!("#{i} - {elapsed}ms")
}
}
```
```
; cargo run
#1 - 1001ms
#2 - 2001ms
#3 - 3001ms
#4 - 4001ms
```
Signed-off-by: katelyn martin <kate@buoyant.io>
Co-authored-by: Alejandro Martinez Ruiz <alex@flawedcode.org>1 parent 921ad6d commit b28453f
1 file changed
Lines changed: 110 additions & 32 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
9 | | - | |
10 | | - | |
| 8 | + | |
11 | 9 | | |
12 | 10 | | |
13 | 11 | | |
| |||
106 | 104 | | |
107 | 105 | | |
108 | 106 | | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | 107 | | |
130 | 108 | | |
131 | 109 | | |
| |||
151 | 129 | | |
152 | 130 | | |
153 | 131 | | |
154 | | - | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
155 | 137 | | |
156 | 138 | | |
157 | 139 | | |
| |||
251 | 233 | | |
252 | 234 | | |
253 | 235 | | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
254 | 239 | | |
255 | | - | |
| 240 | + | |
| 241 | + | |
256 | 242 | | |
257 | 243 | | |
258 | 244 | | |
259 | | - | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
260 | 248 | | |
261 | 249 | | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
268 | 254 | | |
269 | 255 | | |
270 | 256 | | |
| |||
293 | 279 | | |
294 | 280 | | |
295 | 281 | | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
296 | 374 | | |
297 | 375 | | |
298 | 376 | | |
| |||
0 commit comments