p2p: fix conn leak. part of #2046

This commit is contained in:
Ethan Buchman
2018-07-24 21:32:30 -04:00
parent 5768b67162
commit 359898dcac
3 changed files with 10 additions and 2 deletions

View File

@ -496,6 +496,7 @@ func (sw *Switch) listenerRoutine(l Listener) {
maxPeers := sw.config.MaxNumPeers - DefaultMinNumOutboundPeers
if maxPeers <= sw.peers.Size() {
sw.Logger.Info("Ignoring inbound connection: already have enough peers", "address", inConn.RemoteAddr().String(), "numPeers", sw.peers.Size(), "max", maxPeers)
inConn.Close()
continue
}
@ -510,6 +511,7 @@ func (sw *Switch) listenerRoutine(l Listener) {
// cleanup
}
// closes conn if err is returned
func (sw *Switch) addInboundPeerWithConfig(
conn net.Conn,
config *config.P2PConfig,