MCPcopy
hub / github.com/redis/go-redis / isBadConn

Function isBadConn

error.go:185–225  ·  view source on GitHub ↗
(err error, allowTimeout bool, addr string)

Source from the content-addressed store, hash-verified

183}
184
185func isBadConn(err error, allowTimeout bool, addr string) bool {
186 if err == nil {
187 return false
188 }
189
190 // Check for context errors (works with wrapped errors)
191 if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
192 return true
193 }
194
195 // Check for pool timeout errors (works with wrapped errors)
196 if errors.Is(err, pool.ErrConnUnusableTimeout) {
197 return true
198 }
199
200 if isRedisError(err) {
201 switch {
202 case isReadOnlyError(err):
203 // Close connections in read only state in case domain addr is used
204 // and domain resolves to a different Redis Server. See #790.
205 return true
206 case isMovedSameConnAddr(err, addr):
207 // Close connections when we are asked to move to the same addr
208 // of the connection. Force a DNS resolution when all connections
209 // of the pool are recycled
210 return true
211 default:
212 return false
213 }
214 }
215
216 if allowTimeout {
217 // Check for network timeout errors (works with wrapped errors)
218 var netErr net.Error
219 if errors.As(err, &netErr) && netErr.Timeout() {
220 return false
221 }
222 }
223
224 return true
225}
226
227func isMovedError(err error) (moved bool, ask bool, addr string) {
228 // Check for typed MovedError

Callers 5

onAuthenticationErrMethod · 0.85
releaseConnMethod · 0.85
releaseConnMethod · 0.85
pipelineReadCmdsMethod · 0.85

Calls 4

isRedisErrorFunction · 0.85
isReadOnlyErrorFunction · 0.85
isMovedSameConnAddrFunction · 0.85
TimeoutMethod · 0.65

Tested by

no test coverage detected