Commit 0e9f874
fix(net): synchronize Buf.Close with Write/Read to prevent nil-pointer panic
internal/net.Buf had Close() nilling the underlying bytes.Buffer without
taking the rw mutex, racing against concurrent Buf.Write() / Buf.Read()
calls. When the consumer of MultiReadCloser closes mid-download (via
downloader.interrupt()), in-flight chunk-download goroutines could
dereference a nil bytes.Buffer and panic the entire process — matching
the SIGSEGV stack reported in #9190 and one crash mode from #9537.
Make Close acquire the lock and have Read/Write return io.ErrClosedPipe
when the buffer has been nilled, instead of panicking.
Add a race-detector regression test (TestBufCloseWriteRace) that panics
many times without this fix and passes cleanly with it.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent f4445c5 commit 0e9f874
2 files changed
Lines changed: 53 additions & 0 deletions
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
643 | 643 | | |
644 | 644 | | |
645 | 645 | | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
646 | 650 | | |
647 | 651 | | |
648 | 652 | | |
| |||
672 | 676 | | |
673 | 677 | | |
674 | 678 | | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
675 | 682 | | |
676 | 683 | | |
677 | 684 | | |
678 | 685 | | |
679 | 686 | | |
| 687 | + | |
| 688 | + | |
680 | 689 | | |
681 | 690 | | |
0 commit comments