Skip to content

Commit 8fae22f

Browse files
committed
Fix subtle race condition resulting in "Corrupted Buffer detected"
This happened when some subflows are a lot higher latency than the others, this causes a retransmit to reset the state of the RXQ, and then cause the buffer slice to be reset. causing a buffer corruption error to be raised. This bug was detected with bgp.tools clients, running in South Africa
1 parent 3c9cc23 commit 8fae22f

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

multipath/receivequeue.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,13 @@ func (rq *receiveQueue) isFull() bool {
132132
func (rq *receiveQueue) tryAdd(f *rxFrame) bool {
133133
rq.readLock.Lock()
134134
idx := f.fn % rq.size
135-
if rq.buf[idx].bytes == nil {
135+
if rq.buf[idx].fn == f.fn {
136+
rq.readLock.Unlock()
137+
// retransmission, ignore
138+
log.Tracef("Got a retransmit. for %d", f.fn)
139+
pool.Put(f.bytes)
140+
return true
141+
} else if rq.buf[idx].bytes == nil {
136142
// empty slot
137143
rq.buf[idx] = *f
138144
if idx == rq.rp {
@@ -143,12 +149,6 @@ func (rq *receiveQueue) tryAdd(f *rxFrame) bool {
143149
}
144150
rq.readLock.Unlock()
145151
return true
146-
} else if rq.buf[idx].fn == f.fn {
147-
rq.readLock.Unlock()
148-
// retransmission, ignore
149-
log.Tracef("Got a retransmit. for %d", f.fn)
150-
pool.Put(f.bytes)
151-
return true
152152
}
153153
rq.readLock.Unlock()
154154

0 commit comments

Comments
 (0)