diff --git a/CHANGELOG.md b/CHANGELOG.md index e0f9ba907..929d11d97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/p2p/listener.go b/p2p/listener.go index 3509ec69c..d73b3cabf 100644 --- a/p2p/listener.go +++ b/p2p/listener.go @@ -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 } diff --git a/p2p/switch.go b/p2p/switch.go index 636ca6d8e..da94fa4b0 100644 --- a/p2p/switch.go +++ b/p2p/switch.go @@ -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,