Commit 96f514d
authored
fix(comment): bound errored-project rendering to prevent comment-generation hang (#21)
* fix(comment): bound errored-project rendering to prevent comment-generation hang
formatErroredProject built its output with `s += ...` while splitting the
diagnostic message on ": " and applying a per-piece growing indent via
strings.Repeat. A large critical diagnostic (e.g. a multi-MB Terraform HCL
parse error, which also contains many ": " separators) turned this into an
O(n^2) string build, spinning a single goroutine on-CPU indefinitely. This
runs inside GenerateComment, before renderWithTruncation, so the 64KB comment
cap never kicked in.
Fixes:
- formatErroredProject uses strings.Builder, caps each diagnostic message to
4KB before splitting, caps indent depth, and caps the number of critical
diagnostics rendered per project (10) with a summarised remainder.
- processProjectCostDetails caps the combined errored-projects section (32KB),
since the whole section is built before truncation.
Adds a regression test that hangs on the old implementation and completes
instantly with the fix.
* fix(comment): use fmt.Fprintf to satisfy staticcheck QF10121 parent bf087ec commit 96f514d
2 files changed
Lines changed: 132 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
94 | 110 | | |
95 | 111 | | |
96 | 112 | | |
| |||
413 | 429 | | |
414 | 430 | | |
415 | 431 | | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
416 | 454 | | |
417 | | - | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
418 | 459 | | |
419 | 460 | | |
420 | 461 | | |
421 | 462 | | |
422 | | - | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
423 | 473 | | |
424 | | - | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
425 | 480 | | |
426 | | - | |
| 481 | + | |
427 | 482 | | |
428 | | - | |
| 483 | + | |
429 | 484 | | |
430 | 485 | | |
431 | 486 | | |
432 | | - | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
433 | 491 | | |
434 | 492 | | |
435 | 493 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
0 commit comments