Skip to content

Fleet-Server abruptly closes connection when limit is reached instead of returning TooManyRequests (429) #4200

Closed
@belimawr

Description

@belimawr

When limits.max_connections is set, Fleet-Server will abruptly close connections, which makes the clients (usually Elastic-Agent) to get a read: connection reset by peer. This is not helpful and does not enable the client to correctly adapt its behaviour.

The problem comes from the limitListener (L 69):

func (l *limitListener) Accept() (net.Conn, error) {
// Accept the connection irregardless
c, err := l.Listener.Accept()
if err != nil {
return nil, err
}
// If we cannot acquire the semaphore, close the connection
if acquired := l.acquire(); !acquired {
zlog := log.Warn()
var err error
if c != nil {
err = c.Close()
zlog.Str(logger.ECSServerAddress, c.LocalAddr().String())
zlog.Str(logger.ECSClientAddress, c.RemoteAddr().String())
zlog.Err(err)
}
zlog.Int("max", cap(l.sem)).Msg("Connection closed due to max limit")
return c, nil
}
return &limitListenerConn{Conn: c, release: l.release}, nil
}

If there is a proxy in front of Fleet-Server this can cause a very hard situation to debug from the client's (e.g: Elastic-Agent) perspective: Fleet Server gets a connection that is over the limit, closes the connection, which results in an EOF for the proxy, which translates it into a 502, which the elastic-agent enrol command swallows and does not display.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions