{"record":{"id":"c6d0c368d370c07a","repo":"block/buzz","slug":"pubsub-init-failed-e","errorCode":null,"errorMessage":"PubSub init failed: {e}","messagePattern":"PubSub init failed: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/buzz-admin/src/main.rs","lineNumber":572,"sourceCode":"                 The relay must have a stable signing key to publish kind:13534 events.\"\n            )\n        })?;\n        Keys::parse(&hex).map_err(|e| anyhow::anyhow!(\"invalid BUZZ_RELAY_PRIVATE_KEY: {e}\"))?\n    };\n\n    let redis_url =\n        std::env::var(\"REDIS_URL\").unwrap_or_else(|_| \"redis://localhost:6379\".to_string());\n\n    let redis_pool = {\n        let cfg = deadpool_redis::Config::from_url(&redis_url);\n        cfg.create_pool(Some(deadpool_redis::Runtime::Tokio1))\n            .map_err(|e| anyhow::anyhow!(\"Redis pool creation failed: {e}\"))?\n    };\n\n    let pubsub = Arc::new(\n        PubSubManager::new(&redis_url, redis_pool)\n            .await\n            .map_err(|e| anyhow::anyhow!(\"PubSub init failed: {e}\"))?,\n    );\n\n    Ok((db, pubsub, relay_keypair))\n}\n\nasync fn connect_db() -> Result<Db> {\n    let db_url = std::env::var(\"DATABASE_URL\")\n        .unwrap_or_else(|_| \"postgres://buzz:buzz_dev@localhost:5432/buzz\".to_string());\n    let db = Db::new(\n        &DbConfig {\n            database_url: db_url,\n            ..DbConfig::default()\n        }\n        .with_session_timeouts_from_env(),\n    )\n    .await?;\n    Ok(db)\n}","sourceCodeStart":554,"sourceCodeEnd":590,"githubUrl":"https://github.com/block/buzz/blob/ef2aa1ae38fadcc0bc22b8bf6ed96b35933146be/crates/buzz-admin/src/main.rs#L554-L590","documentation":"Unlike pool creation, PubSubManager::new actually dials Redis to set up pub/sub plumbing. It fails on live connection problems: server unreachable (connection refused / DNS failure / firewall), auth failure (requirepass with no password or wrong one), or a Redis version/protocol mismatch. The wrapped {e} carries the underlying redis error.","triggerScenarios":"REDIS_URL points at a Redis that is down or firewalled; Redis requires a password and the URL lacks :password@; TLS mismatch (redis:// against a TLS-only port); k8s service not ready when the admin job starts.","commonSituations":"Running buzz-admin add-member without starting the docker-compose redis; rotating Redis credentials without updating REDIS_URL; job races a starting container.","solutions":["Health-check with the same URL: redis-cli -u \"$REDIS_URL\" ping (expect PONG).","Start Redis (docker compose up -d redis) or fix the host/port in REDIS_URL.","Embed credentials if needed: redis://:password@host:6379, and rediss:// for TLS.","If the job races container startup, add a readiness wait on the Redis port before invoking buzz-admin."],"exampleFix":"# before\nREDIS_URL=redis://redis:6379  # container still starting -> PubSub init failed\n# after\nuntil redis-cli -u \"$REDIS_URL\" ping 2>/dev/null | grep -q PONG; do sleep 1; done\nbuzz-admin add-member --pubkey <hex> --role member","handlingStrategy":"retry","validationCode":"# preflight: prove Redis is reachable with the exact URL before the CLI runs\nredis-cli -u \"$REDIS_URL\" ping | grep -q PONG || { echo 'Redis not ready' >&2; exit 3; }","typeGuard":null,"tryCatchPattern":"// wrap admin invocations with bounded retry only for connection-class failures\nfor attempt in 0..3 {\n    match run(cmd).await {\n        Ok(v) => return Ok(v),\n        Err(e) if e.to_string().contains(\"PubSub init failed\") && attempt < 2 => {\n            backoff(attempt).await;  // Redis may still be starting; retry with delay\n        }\n        Err(e) => return Err(e),   // auth/config failures will not heal — surface immediately\n    }\n}","preventionTips":["Gate admin jobs on a Redis readiness probe (redis-cli PING) instead of a fixed sleep.","Keep the relay's and the CLI's REDIS_URL identical — one secret, two consumers.","Include the password in the URL when Redis requires auth; test with the same URL the CLI uses."],"tags":["buzz-admin","redis","pubsub","connection","buzz-pubsub"],"backgroundTag":"redis-connection-failed","analyzedSha":"ef2aa1ae38fadcc0bc22b8bf6ed96b35933146be","analyzedAt":"2026-08-20T04:38:24.874Z","contentChangedAt":"2026-08-20T04:38:24.874Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}