server: Stop main loop from blocking when RPC server is not running.
When the RPC server is not running a buffered transaction notification channel fills and eventually blocks. This commit ensures that the channel continues to be drained irrespective of the RPC server status.
This commit is contained in:
parent
e08038115b
commit
391d5e4a01
1 changed files with 37 additions and 9 deletions
46
server.go
46
server.go
|
@ -1954,14 +1954,10 @@ func (s *server) UpdatePeerHeights(latestBlkSha *wire.ShaHash, latestHeight int3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// rebroadcastHandler keeps track of user submitted inventories that we have
|
// relayTransactionsHandler relays transactions sent on relayNtfnChan to other
|
||||||
// sent out but have not yet made it into a block. We periodically rebroadcast
|
// peers and to the RPC infrastructure if necessary. It must be run as a
|
||||||
// them in case our peers restarted or otherwise lost track of them.
|
// goroutine.
|
||||||
func (s *server) rebroadcastHandler() {
|
func (s *server) relayTransactionsHandler() {
|
||||||
// Wait 5 min before first tx rebroadcast.
|
|
||||||
timer := time.NewTimer(5 * time.Minute)
|
|
||||||
pendingInvs := make(map[wire.InvVect]interface{})
|
|
||||||
|
|
||||||
out:
|
out:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -1976,9 +1972,38 @@ out:
|
||||||
|
|
||||||
// Potentially notify any getblocktemplate long poll clients
|
// Potentially notify any getblocktemplate long poll clients
|
||||||
// about stale block templates due to the new transaction.
|
// about stale block templates due to the new transaction.
|
||||||
s.rpcServer.gbtWorkState.NotifyMempoolTx(s.txMemPool.LastUpdated())
|
s.rpcServer.gbtWorkState.NotifyMempoolTx(
|
||||||
|
s.txMemPool.LastUpdated())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case <-s.quit:
|
||||||
|
break out
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drain channels before exiting so nothing is left waiting around to send.
|
||||||
|
cleanup:
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-s.relayNtfnChan:
|
||||||
|
default:
|
||||||
|
break cleanup
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s.wg.Done()
|
||||||
|
}
|
||||||
|
|
||||||
|
// rebroadcastHandler keeps track of user submitted inventories that we have
|
||||||
|
// sent out but have not yet made it into a block. We periodically rebroadcast
|
||||||
|
// them in case our peers restarted or otherwise lost track of them.
|
||||||
|
func (s *server) rebroadcastHandler() {
|
||||||
|
// Wait 5 min before first tx rebroadcast.
|
||||||
|
timer := time.NewTimer(5 * time.Minute)
|
||||||
|
pendingInvs := make(map[wire.InvVect]interface{})
|
||||||
|
|
||||||
|
out:
|
||||||
|
for {
|
||||||
|
select {
|
||||||
case riv := <-s.modifyRebroadcastInv:
|
case riv := <-s.modifyRebroadcastInv:
|
||||||
switch msg := riv.(type) {
|
switch msg := riv.(type) {
|
||||||
// Incoming InvVects are added to our map of RPC txs.
|
// Incoming InvVects are added to our map of RPC txs.
|
||||||
|
@ -2047,6 +2072,9 @@ func (s *server) Start() {
|
||||||
s.wg.Add(1)
|
s.wg.Add(1)
|
||||||
go s.peerHandler()
|
go s.peerHandler()
|
||||||
|
|
||||||
|
s.wg.Add(1)
|
||||||
|
go s.relayTransactionsHandler()
|
||||||
|
|
||||||
if s.nat != nil {
|
if s.nat != nil {
|
||||||
s.wg.Add(1)
|
s.wg.Add(1)
|
||||||
go s.upnpUpdateThread()
|
go s.upnpUpdateThread()
|
||||||
|
|
Loading…
Reference in a new issue