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()
}
func (r *cachedReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
func (r *cachedReader) readInternal() buf.MultiBuffer {
r.Lock()
defer r.Unlock()
if r.cache != nil && !r.cache.IsEmpty() {
mb := r.cache
r.cache = nil
return mb
}
return nil
}
func (r *cachedReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
mb := r.readInternal()
if 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) {
r.Lock()
defer r.Unlock()
if r.cache != nil && !r.cache.IsEmpty() {
mb := r.cache
r.cache = nil
mb := r.readInternal()
if mb != nil {
return mb, nil
}

Loading…
Cancel
Save