Browse Source

p2p: fix conn leak. part of #2046

pull/2056/head
Ethan Buchman 6 years ago
parent
commit
359898dcac
3 changed files with 10 additions and 2 deletions
  1. +5
    -1
      CHANGELOG.md
  2. +3
    -1
      p2p/listener.go
  3. +2
    -0
      p2p/switch.go

+ 5
- 1
CHANGELOG.md View File

@ -10,7 +10,11 @@ BUG FIXES
- (#2049) Fix OOM attack by returning error on negative input
- Fix result length to have max 20 (instead of 21) block metas
- [rpc] Validate height is non-negative in `/abci_query`
- [Gopkg] Fix versions in the toml
- [consensus] (#2050) Include evidence in proposal block parts (previously evidence was
not being included in blocks!)
- [p2p] (#2046) Close rejected inbound connections so file descriptor doesn't
leak
- [Gopkg] (#2053) Fix versions in the toml
## 0.22.5


+ 3
- 1
p2p/listener.go View File

@ -151,7 +151,7 @@ func (l *DefaultListener) OnStop() {
l.listener.Close() // nolint: errcheck
}
// Accept connections and pass on the channel
// Accept connections and pass on the channel.
func (l *DefaultListener) listenRoutine() {
for {
conn, err := l.listener.Accept()
@ -178,6 +178,8 @@ func (l *DefaultListener) listenRoutine() {
// Connections returns a channel of inbound connections.
// It gets closed when the listener closes.
// It is the callers responsibility to close any connections received
// over this channel.
func (l *DefaultListener) Connections() <-chan net.Conn {
return l.connections
}


+ 2
- 0
p2p/switch.go 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,


Loading…
Cancel
Save