Skip to content

Commit fdbb676

Browse files
author
HaoyangLiu
committed
Fix mempool reactor goroutine leak
1 parent a7e5123 commit fdbb676

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

mempool/reactor.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,21 @@ func (memR *MempoolReactor) broadcastTxRoutine(peer p2p.Peer) {
116116

117117
var next *clist.CElement
118118
for {
119+
select {
120+
case <-peer.Quit():
121+
return
122+
case <-memR.Quit():
123+
return
124+
default:
125+
// continue to broadcast transaction
126+
}
119127
// This happens because the CElement we were looking at got garbage
120128
// collected (removed). That is, .NextWait() returned nil. Go ahead and
121129
// start from the beginning.
122130
if next == nil {
123-
select {
124-
case <-memR.Mempool.TxsWaitChan(): // Wait until a tx is available
125-
if next = memR.Mempool.TxsFront(); next == nil {
126-
continue
127-
}
128-
case <-peer.Quit():
129-
return
130-
case <-memR.Quit():
131-
return
131+
<-memR.Mempool.TxsWaitChan() // Wait until a tx is available
132+
if next = memR.Mempool.TxsFront(); next == nil {
133+
continue
132134
}
133135
}
134136

0 commit comments

Comments
 (0)