mirror of
https://github.com/alist-org/alist.git
synced 2026-07-21 21:14:07 +08:00
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]>