fix a deadlock in cacheReader. fix #1471

pull/1465/head
Darien Raymond 6 years ago
parent 372da062d4
commit 0ca762e0e2
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

@ -46,13 +46,22 @@ func (r *cachedReader) Cache(b *buf.Buffer) {
r.Unlock() r.Unlock()
} }
func (r *cachedReader) ReadMultiBuffer() (buf.MultiBuffer, error) { func (r *cachedReader) readInternal() buf.MultiBuffer {
r.Lock() r.Lock()
defer r.Unlock() defer r.Unlock()
if r.cache != nil && !r.cache.IsEmpty() { if r.cache != nil && !r.cache.IsEmpty() {
mb := r.cache mb := r.cache
r.cache = nil r.cache = nil
return mb
}
return nil
}
func (r *cachedReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
mb := r.readInternal()
if mb != nil {
return mb, nil return mb, nil
} }
@ -60,12 +69,8 @@ func (r *cachedReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
} }
func (r *cachedReader) ReadMultiBufferTimeout(timeout time.Duration) (buf.MultiBuffer, error) { func (r *cachedReader) ReadMultiBufferTimeout(timeout time.Duration) (buf.MultiBuffer, error) {
r.Lock() mb := r.readInternal()
defer r.Unlock() if mb != nil {
if r.cache != nil && !r.cache.IsEmpty() {
mb := r.cache
r.cache = nil
return mb, nil return mb, nil
} }

Loading…
Cancel
Save