Commit 14fff05
committed
fix(asg): guard release_instances against double capacity decrement
After commit 641a033 introduced the IN_PROGRESS-then-COMPLETED return
flow, ASG partial-return tests started seeing DesiredCapacity drop by 2
(e.g. 4→2) when only 1 instance was returned (expected 4→3).
Root cause: release_instances calls detach_instances with
ShouldDecrementDesiredCapacity=True, which atomically decrements
DesiredCapacity. If the method is invoked a second time for the same
instance before the instance is confirmed terminated (possible under the
new IN_PROGRESS polling window), the decrement fires again on an already-
detached instance.
Fix: add _filter_asg_members() to query describe_auto_scaling_instances
before detaching. Only instances that are currently attached to the ASG
are included in the detach call. Instances already detached are skipped
(no capacity decrement), but are still forwarded to
terminate_instances_with_fallback so they are cleaned up.
Also corrects the fallback live_desired calculation to use
len(instances_to_detach) instead of len(instance_ids), keeping the
capacity arithmetic consistent when a subset is detached.
Adds a moto regression test (test_asg_partial_return_idempotent_capacity_
not_double_decremented) that calls release_hosts twice for the same
instance and asserts DesiredCapacity stays at N-1, not N-2.1 parent 94f39f4 commit 14fff05
2 files changed
Lines changed: 135 additions & 3 deletions
File tree
- src/orb/providers/aws/infrastructure/handlers/asg
- tests/providers/aws/moto
Lines changed: 64 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
175 | 202 | | |
176 | | - | |
| 203 | + | |
177 | 204 | | |
178 | 205 | | |
179 | 206 | | |
| |||
182 | 209 | | |
183 | 210 | | |
184 | 211 | | |
185 | | - | |
| 212 | + | |
186 | 213 | | |
187 | 214 | | |
188 | 215 | | |
| |||
201 | 228 | | |
202 | 229 | | |
203 | 230 | | |
204 | | - | |
| 231 | + | |
205 | 232 | | |
206 | 233 | | |
207 | 234 | | |
| |||
228 | 255 | | |
229 | 256 | | |
230 | 257 | | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
231 | 292 | | |
232 | 293 | | |
233 | 294 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
467 | 467 | | |
468 | 468 | | |
469 | 469 | | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
470 | 541 | | |
471 | 542 | | |
472 | 543 | | |
| |||
0 commit comments