Properly reconnect in lql.Client

master
René Jochum 4 years ago
parent 594c1585f8
commit 0cb63b008d

@ -70,6 +70,11 @@ func (p *GncpPool) init() error {
return nil
}
// GetMaxConns returns the maximum number of connections configured
func (p *GncpPool) GetMaxConns() int {
return p.maxConnNum
}
// Get get connection from connection pool. If connection poll is empty and alreay created connection number less than Max number of connection
// it will create new one. Otherwise it wil wait someone put connection back.
func (p *GncpPool) Get() (net.Conn, error) {

@ -174,13 +174,15 @@ func (c *Client) RequestRaw(context context.Context, request, outputFormat, auth
c.logger.WithField("request", request).Debug("Writing request")
_, err = conn.Write([]byte(request))
if err != nil && errors.Is(err, syscall.EPIPE) {
if err != nil && !errors.Is(err, syscall.EPIPE) {
return nil, err
} else if errors.Is(err, syscall.EPIPE) {
// Destroy -> Create Connections until we don't get EPIPE.
numTries := 0
for errors.Is(err, syscall.EPIPE) {
c.logger.WithField("error", err).Debug("Trying to reconnect")
conn.Close()
conn.(*gncp.CpConn).Destroy()
@ -196,7 +198,8 @@ func (c *Client) RequestRaw(context context.Context, request, outputFormat, auth
}
numTries++
if numTries >= 20 {
if numTries >= c.pool.GetMaxConns()*2 {
c.logger.WithField("error", err).Error("To much retries can't reconnect")
// Bailout to much tries
return nil, err
}

Loading…
Cancel
Save