p2p : fix quit channel goroutine leak

This commit is contained in:
ucwong 2020-04-03 08:48:12 +00:00
parent f7b29ec942
commit fa82dcb63d
8 changed files with 13 additions and 13 deletions

View file

@ -105,8 +105,8 @@ func newTable(t transport, db *enode.DB, bootnodes []*enode.Node, log log.Logger
db: db,
refreshReq: make(chan chan struct{}),
initDone: make(chan struct{}),
closeReq: make(chan struct{}),
closed: make(chan struct{}),
closeReq: make(chan struct{}, 1),
closed: make(chan struct{}, 1),
rand: mrand.New(mrand.NewSource(0)),
ips: netutil.DistinctNetSet{Subnet: tableSubnet, Limit: tableIPLimit},
log: log,
@ -205,7 +205,7 @@ func (tab *Table) isInitDone() bool {
}
func (tab *Table) refresh() <-chan struct{} {
done := make(chan struct{})
done := make(chan struct{}, 1)
select {
case tab.refreshReq <- done:
case <-tab.closeReq:

View file

@ -85,7 +85,7 @@ func newMemoryNodeDB(self NodeID) (*nodeDB, error) {
return &nodeDB{
lvl: db,
self: self,
quit: make(chan struct{}),
quit: make(chan struct{}, 1),
}, nil
}
@ -127,7 +127,7 @@ func newPersistentNodeDB(path string, version int, self NodeID) (*nodeDB, error)
return &nodeDB{
lvl: db,
self: self,
quit: make(chan struct{}),
quit: make(chan struct{}, 1),
}, nil
}

View file

@ -144,8 +144,8 @@ func newNetwork(conn transport, ourPubkey ecdsa.PublicKey, dbPath string, netres
ticketStore: newTicketStore(),
refreshReq: make(chan []*Node),
refreshResp: make(chan (<-chan struct{})),
closed: make(chan struct{}),
closeReq: make(chan struct{}),
closed: make(chan struct{}, 1),
closeReq: make(chan struct{}, 1),
read: make(chan ingressPacket, 100),
timeout: make(chan timeoutEvent),
timeoutTimers: make(map[timeoutEvent]*time.Timer),

View file

@ -160,7 +160,7 @@ type mixSource struct {
func NewFairMix(timeout time.Duration) *FairMix {
m := &FairMix{
fromAny: make(chan *Node),
closed: make(chan struct{}),
closed: make(chan struct{}, 1),
timeout: timeout,
}
return m

View file

@ -85,7 +85,7 @@ func newMemoryDB() (*DB, error) {
if err != nil {
return nil, err
}
return &DB{lvl: db, quit: make(chan struct{})}, nil
return &DB{lvl: db, quit: make(chan struct{}, 1)}, nil
}
// newPersistentNodeDB creates/opens a leveldb backed persistent node database,
@ -123,7 +123,7 @@ func newPersistentDB(path string) (*DB, error) {
return newPersistentDB(path)
}
}
return &DB{lvl: db, quit: make(chan struct{})}, nil
return &DB{lvl: db, quit: make(chan struct{}, 1)}, nil
}
// nodeKey returns the database key for a node record.

View file

@ -153,7 +153,7 @@ func (r *eofSignal) Read(buf []byte) (int, error) {
func MsgPipe() (*MsgPipeRW, *MsgPipeRW) {
var (
c1, c2 = make(chan Msg), make(chan Msg)
closing = make(chan struct{})
closing = make(chan struct{}, 1)
closed = new(int32)
rw1 = &MsgPipeRW{c1, c2, closing, closed}
rw2 = &MsgPipeRW{c2, c1, closing, closed}

View file

@ -187,7 +187,7 @@ func newPeer(log log.Logger, conn *conn, protocols []Protocol) *Peer {
created: mclock.Now(),
disc: make(chan DiscReason),
protoErr: make(chan error, len(protomap)+1), // protocols + pingLoop
closed: make(chan struct{}),
closed: make(chan struct{}, 1),
log: log.New("id", conn.node.ID(), "conn", conn.flags),
}
return p

View file

@ -462,7 +462,7 @@ func (srv *Server) Start() (err error) {
if srv.listenFunc == nil {
srv.listenFunc = net.Listen
}
srv.quit = make(chan struct{})
srv.quit = make(chan struct{}, 1)
srv.delpeer = make(chan peerDrop)
srv.checkpointPostHandshake = make(chan *conn)
srv.checkpointAddPeer = make(chan *conn)