{"record":{"id":"4cdb2f6665b44df0","repo":"juspay/hyperswitch","slug":"failed-to-subscribe-on-authenticated-connection","errorCode":null,"errorMessage":"failed to subscribe on authenticated connection","messagePattern":"failed to subscribe on authenticated connection","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/redis_interface/src/test.rs","lineNumber":2379,"sourceCode":"}\n\n#[tokio::test]\nasync fn test_authenticated_connection_pubsub() {\n    let is_success = tokio::task::spawn_blocking(move || {\n        futures::executor::block_on(async {\n            let Some(pool) = get_auth_pool_or_skip().await else {\n                tracing::warn!(\"SKIP: auth test skipped — set TEST_REDIS_AUTH_PASSWORD to enable\");\n                return true;\n            };\n\n            let channel = format!(\"test_auth_pubsub_{}\", unique_test_id());\n            let test_message = \"authenticated_message\";\n\n            pool.redis_conn\n                .subscriber\n                .subscribe(&channel)\n                .await\n                .expect(\"failed to subscribe on authenticated connection\");\n\n            let mut receiver = pool.redis_conn.subscriber.message_rx();\n\n            tokio::time::sleep(std::time::Duration::from_millis(100)).await;\n\n            pool.redis_conn\n                .publisher\n                .publish(&channel, RedisValue::from_string(test_message.to_string()))\n                .await\n                .expect(\"failed to publish on authenticated connection\");\n\n            let received =\n                tokio::time::timeout(std::time::Duration::from_secs(5), receiver.recv()).await;\n\n            match received {\n                Ok(Ok(msg)) => {\n                    let value_str = redis_value_to_option_string(&msg.value);\n                    msg.channel == channel && value_str.as_deref() == Some(test_message)","sourceCodeStart":2361,"sourceCodeEnd":2397,"githubUrl":"https://github.com/juspay/hyperswitch/blob/afd92843521ced2c6856b98ae4ea332e75102d88/crates/redis_interface/src/test.rs#L2361-L2397","documentation":"Panic from expect() on subscriber.subscribe(&channel).await in test_authenticated_connection_pubsub (crates/redis_interface/src/test.rs:2379). The RedisInterface subscriber (pubsub connection) failed to issue SUBSCRIBE on the channel over the authenticated connection, so the future returned Err and the test aborts with this message. It means the dedicated pubsub connection could not be established or the SUBSCRIBE command was rejected.","triggerScenarios":"Calling pool.redis_conn.subscriber.subscribe(&channel) when the pubsub connection can't be created (auth failure, unreachable server), or Redis rejects the subscribe (e.g. running against a cluster where the node mapping fails, or the connection is in an invalid state after an error).","commonSituations":"Authenticated Redis misconfigured (wrong password so pubsub reconnect fails); cluster mode with channel-keyslot restrictions; pubsub connection dropped by server timeout before subscribe; tests running without Redis so the subscriber pool init fails.","solutions":["Ensure the base authenticated connection works first (other tests in the suite pass); fix credentials/host if the pool itself can't authenticate.","If using Redis cluster, subscribe on the node that owns the channel's keyslot or enable cluster-aware pubsub routing in the subscriber.","Create the subscriber/pool immediately before subscribing and add a small sleep so the pubsub task is connected before subscribe() is called.","Inspect the underlying redis error (subscribe returns the raw error) — match on it to distinguish auth vs network vs protocol issues instead of a bare expect."],"exampleFix":"// before\npool.redis_conn\n    .subscriber\n    .subscribe(&channel)\n    .await\n    .expect(\"failed to subscribe on authenticated connection\");\n// after\npool.redis_conn\n    .subscriber\n    .subscribe(&channel)\n    .await\n    .unwrap_or_else(|e| panic!(\"failed to subscribe on {channel}: {e:?}\"));","handlingStrategy":"try-catch","validationCode":"// before subscribing, confirm a plain connection works:\n// let mut conn = pool.redis_conn.publisher.clone();\n// redis::cmd(\"PING\").query_async::<()>(&mut conn).await.expect(\"ping failed\");","typeGuard":null,"tryCatchPattern":"pool.redis_conn.subscriber.subscribe(&channel).await\n    .unwrap_or_else(|e| panic!(\"failed to subscribe on {channel}: {e:?}\"));","preventionTips":["Verify base authentication works before testing pubsub paths","On Redis cluster, subscribe via the node owning the channel keyslot or enable cluster pubsub routing","Allow a readiness delay after pool creation before subscribing","Log the raw subscribe error rather than a bare expect string"],"tags":["redis","pubsub","subscribe","test-infrastructure","panic"],"backgroundTag":"connection-refused","analyzedSha":"afd92843521ced2c6856b98ae4ea332e75102d88","analyzedAt":"2026-09-18T01:18:02.947Z","contentChangedAt":"2026-09-18T01:18:02.947Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}