Files
alist/internal/net
okatu-loliandClaude Opus 4.7 0e9f874637 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 <[email protected]>
2026-05-29 09:37:13 +08:00
..