{"record":{"id":"cc2ec107234c2e03","repo":"Billionmail/BillionMail","slug":"redis-connection-test-failed-after-10-attempts","errorCode":null,"errorMessage":"redis connection test failed after 10 attempts","messagePattern":"redis connection test failed after 10 attempts","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"core/internal/service/redis_initialization/redis_initialization.go","lineNumber":65,"sourceCode":"\t\tif err := g.Redis().SetEX(context.Background(), k, k, 1); err != nil {\n\t\t\tg.Log().Error(context.Background(), \"Redis connection test failed: \", err, \" Waiting for 5 seconds before retrying...\")\n\t\t\ttime.Sleep(5 * time.Second)\n\t\t\tcontinue\n\t\t}\n\n\t\tif _, err := g.Redis().Del(context.Background(), k); err != nil {\n\t\t\tg.Log().Error(context.Background(), \"Redis connection test failed: \", err, \" Waiting for 5 seconds before retrying...\")\n\t\t\ttime.Sleep(5 * time.Second)\n\t\t\tcontinue\n\t\t}\n\n\t\tconnectionOK = true\n\t\tg.Log().Debug(context.Background(), \"Redis connection test successful\")\n\t\tbreak\n\t}\n\n\tif !connectionOK {\n\t\treturn fmt.Errorf(\"redis connection test failed after 10 attempts\")\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":47,"sourceCodeEnd":70,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/redis_initialization/redis_initialization.go#L47-L70","documentation":"InitRedis tries up to 10 times to connect to Redis and run a connectivity test before the application will start. If every attempt fails (e.g. Redis is down, unreachable, or misconfigured), it returns this sentinel error indicating the connection test never succeeded after exhausting all retries. It is thrown because the app depends on Redis at boot and cannot proceed without a verified connection.","triggerScenarios":"All 10 loop iterations of the connection test fail — Redis service not running, wrong host/port in config, Redis still starting during container orchestration, network/DNS failure, or wrong password (requirepass).","commonSituations":"Docker Compose where Redis container is not up yet when the app starts; REDIS_HOST pointing at localhost inside a container; Redis restarted/crashed; firewall or Docker network misconfiguration; auth misconfiguration.","solutions":["Verify Redis is running: docker ps / redis-cli -h <host> -p 6379 ping","Check Redis connection config (host, port, password) in the app's config file or environment","Increase retry window or add depends_on/healthcheck so Redis is ready before the app starts","Test connectivity from the app's network context (same Docker network, no firewall block)","Inspect app logs for the underlying per-attempt error (auth vs refused vs timeout)"],"exampleFix":"// before (docker-compose.yml)\nservices:\n  app:\n    depends_on: [redis]\n// after\nservices:\n  app:\n    depends_on:\n      redis:\n        condition: service_healthy","handlingStrategy":"retry","validationCode":"func redisReachable(addr string) error {\n    conn, err := net.DialTimeout(\"tcp\", addr, 2*time.Second)\n    if err != nil { return err }\n    return conn.Close()\n}\n// call before starting the app: if err := redisReachable(\"127.0.0.1:6379\"); err != nil { log.Fatal(err) }","typeGuard":null,"tryCatchPattern":"if err := redis_initialization.InitRedis(); err != nil {\n    if strings.Contains(err.Error(), \"connection test failed\") {\n        // back off and retry startup, or fall back to degraded mode\n        time.Sleep(5 * time.Second)\n        return retryInit(3)\n    }\n    return err\n}","preventionTips":["Add a Redis healthcheck to docker-compose with depends_on condition: service_healthy","Externalize Redis host/port/password in config and validate at boot","Use exponential backoff retries in InitRedis instead of fixed 10 fast attempts","Alert on Redis restarts/unavailability in production"],"tags":["redis","connection","startup","retry"],"backgroundTag":"connection-refused","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}