1

I'm using redigo in go with docker. I have a server that processes incoming events and uses redis for rate limiting. One in every 100k+ connections or so I get the following error:

redis: dial tcp IP ADDRESS: connect: connection refused

The configuration is all inside docker using docker-compose. I've got sentry sending me these errors, I was wondering if there were any tweaks/settings I could do to remove/reduce this error

My redigo configuration is

redis := &redis.Pool{
    MaxActive: idleConnections,
    MaxIdle:   idleConnections,
    Wait:      true,
    Dial: func() (redis.Conn, error) {
        return redis.Dial("tcp", address, options...)
    },
}
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Schroedinger
  • 1,273
  • 14
  • 32

1 Answers1

1

You could retry the dial using some sort of exponential backoff:

Dial: func() (redis.Conn, error) {
    c, err := redis.Dial("tcp", address, options...)
    for retries := 0; err != nil && retries < 5; retries++ {
        time.Sleep((50 << retries) * time.Millisecond)
        c, err = redis.Dial("tcp", address, options...)
    }
    return c, err
},
dave
  • 62,300
  • 5
  • 72
  • 93