fix(net): Buf use Mutex (#5823)

Co-authored-by: Andy Hsu <i@nn.ci>
This commit is contained in:
Rammiah 2024-01-05 12:20:08 +08:00 committed by GitHub
parent 8020d42b10
commit 4448e08f5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -449,7 +449,7 @@ type Buf struct {
size int //expected size size int //expected size
ctx context.Context ctx context.Context
off int off int
rw sync.RWMutex rw sync.Mutex
//notify chan struct{} //notify chan struct{}
} }
@ -480,9 +480,9 @@ func (br *Buf) Read(p []byte) (n int, err error) {
if br.off >= br.size { if br.off >= br.size {
return 0, io.EOF return 0, io.EOF
} }
br.rw.RLock() br.rw.Lock()
n, err = br.buffer.Read(p) n, err = br.buffer.Read(p)
br.rw.RUnlock() br.rw.Unlock()
if err == nil { if err == nil {
br.off += n br.off += n
return n, err return n, err