Commit 03da8ab
fix: release P2P channel receive buffer after large message EOF (#2815)
## Summary
- Replace `ch.recving = ch.recving[:0]` with `ch.recving = make([]byte,
0, ch.desc.RecvBufferCapacity)` in `Channel.recvPacketMsg` so that large
backing arrays are released to GC after message completion instead of
being retained for the connection lifetime.
- Add unit tests verifying buffer capacity resets to baseline after
single-packet and multi-packet large messages.
## Rationale
A remote peer can pin large heap allocations (~128 MiB per connection on
the BLOCKSYNC channel) by sending one large message and keeping the
connection open. With 40 default inbound peers, this enables ~5 GiB of
pinned heap leading to OOM. The fix ensures the receive buffer shrinks
back to its baseline capacity (default 4 KiB) after each message
completes.
## Test plan
- [x] `TestRecvPacketMsgReleasesBufferAfterLargeMessage` — verifies
buffer cap returns to baseline after a single large EOF message
- [x] `TestRecvPacketMsgMultiPacketMessage` — verifies buffer cap
returns to baseline after multi-chunk reassembly
- [x] All existing `p2p/conn` tests pass
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
(cherry picked from commit dc43229)1 parent 252b1bd commit 03da8ab
2 files changed
Lines changed: 79 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
899 | 899 | | |
900 | 900 | | |
901 | 901 | | |
902 | | - | |
903 | | - | |
904 | | - | |
905 | | - | |
906 | | - | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
907 | 907 | | |
908 | 908 | | |
909 | 909 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
618 | 618 | | |
619 | 619 | | |
620 | 620 | | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
621 | 695 | | |
622 | 696 | | |
623 | 697 | | |
| |||
0 commit comments