mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 23:47:07 -05:00
fix data race in ray
This commit is contained in:
parent
60f3562ac1
commit
5ae8bfbda1
@ -143,26 +143,38 @@ func (s *Stream) ReadTimeout(timeout time.Duration) (buf.MultiBuffer, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Stream) Write(data buf.MultiBuffer) error {
|
func (s *Stream) waitForStreamSize() error {
|
||||||
if data.IsEmpty() {
|
if streamSizeLimit == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.access.RLock()
|
||||||
|
defer s.access.RUnlock()
|
||||||
|
|
||||||
for streamSizeLimit > 0 && s.size >= streamSizeLimit {
|
for streamSizeLimit > 0 && s.size >= streamSizeLimit {
|
||||||
select {
|
select {
|
||||||
case <-s.ctx.Done():
|
case <-s.ctx.Done():
|
||||||
return io.ErrClosedPipe
|
return io.ErrClosedPipe
|
||||||
case <-s.readSignal:
|
case <-s.readSignal:
|
||||||
s.access.RLock()
|
|
||||||
if s.err || s.close {
|
if s.err || s.close {
|
||||||
data.Release()
|
|
||||||
s.access.RUnlock()
|
|
||||||
return io.ErrClosedPipe
|
return io.ErrClosedPipe
|
||||||
}
|
}
|
||||||
s.access.RUnlock()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Stream) Write(data buf.MultiBuffer) error {
|
||||||
|
if data.IsEmpty() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := s.waitForStreamSize(); err != nil {
|
||||||
|
data.Release()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
s.access.Lock()
|
s.access.Lock()
|
||||||
defer s.access.Unlock()
|
defer s.access.Unlock()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user