{"record":{"id":"a9ac67b6f7696535","repo":"redis/jedis","slug":"blocking-pub-sub-operations-are-not-supported-on-t","errorCode":null,"errorMessage":"Blocking pub/sub operations are not supported on token-based authentication enabled connections with RESP2 protocol!","messagePattern":"Blocking pub/sub operations are not supported on token-based authentication enabled connections with RESP2 protocol!","errorType":"exception","errorClass":"JedisException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/JedisPubSubBase.java","lineNumber":65,"sourceCode":"\n  public final void unsubscribe(T... channels) {\n    sendAndFlushCommand(Command.UNSUBSCRIBE, channels);\n  }\n\n  public final void subscribe(T... channels) {\n    checkConnectionSuitableForPubSub();\n    sendAndFlushCommand(Command.SUBSCRIBE, channels);\n  }\n\n  public final void psubscribe(T... patterns) {\n    checkConnectionSuitableForPubSub();\n    sendAndFlushCommand(Command.PSUBSCRIBE, patterns);\n  }\n\n  private void checkConnectionSuitableForPubSub() {\n    if (authenticator.client.getRedisProtocol() != RedisProtocol.RESP3\n        && authenticator.client.isTokenBasedAuthenticationEnabled()) {\n      throw new JedisException(\n          \"Blocking pub/sub operations are not supported on token-based authentication enabled connections with RESP2 protocol!\");\n    }\n  }\n\n  public final void punsubscribe() {\n    sendAndFlushCommand(Command.PUNSUBSCRIBE);\n  }\n\n  public final void punsubscribe(T... patterns) {\n    sendAndFlushCommand(Command.PUNSUBSCRIBE, patterns);\n  }\n\n  public final void ping() {\n    authenticator.commandSync.lock();\n    try {\n      sendAndFlushCommand(Command.PING);\n      authenticator.resultHandler.add(pingResultHandler);\n    } finally {","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/JedisPubSubBase.java#L47-L83","documentation":"With RESP2 there is no push-type notification, so token-based (ACL credential/credential-provider) authentication that needs re-authentication via client tracking/refresh cannot run concurrently with blocking pub/sub reads; a blocked subscribe loop would prevent token renewal and the connection could be revoked mid-stream. Jedis deliberately rejects the combination: subscribe/psubscribe on a connection that both uses token-based authentication and negotiates RESP2 throws this JedisException from checkConnectionSuitableForPubSub (JedisPubSubBase.java:65).","triggerScenarios":"Calling subscribe(), psubscribe() (or the lazySubscribe equivalents) on a connection whose JedisClientConfig enables token-based authentication (e.g. CredentialProvider with renewal) while the protocol is RESP2 (protocol default or explicitly set to ProtocolVersion.RESP2).","commonSituations":"Using Redis 6 ACL credentials with a credential provider on default RESP2 protocol; forgetting to set .protocol(RedisProtocol.RESP3) in the client config when token-based auth is on, then subscribing to channels.","solutions":["Set protocol RESP3 in the client config: config.protocol(RedisProtocol.RESP3), which supports push messages alongside token auth.","Disable token-based authentication on the subscribing connection (use static password) if RESP2 must be kept.","Use a separate connection/client for pub/sub with non-token (static) credentials."],"exampleFix":"// before\nJedisClientConfig config = new DefaultJedisClientConfig.Builder()\n    .credentialProvider(provider)\n    .build(); // RESP2 default -> throws on subscribe\n\n// after\nJedisClientConfig config = new DefaultJedisClientConfig.Builder()\n    .credentialProvider(provider)\n    .protocol(RedisProtocol.RESP3)\n    .build();","handlingStrategy":"validation","validationCode":"if (clientConfig.getCredentialProvider() != null\n    && clientConfig.getRedisProtocol() != RedisProtocol.RESP3) {\n  // switch to RESP3 or use static credentials before subscribing\n}","typeGuard":null,"tryCatchPattern":"try {\n  pubSub.subscribe(jedis, channel);\n} catch (JedisException e) {\n  if (e.getMessage().contains(\"token-based authentication\")) {\n    jedis = openConnectionWithResp3(config.protocol(RedisProtocol.RESP3));\n    pubSub.subscribe(jedis, channel);\n  }\n}","preventionTips":["Always set protocol RESP3 when using token-based/credential-provider auth.","Keep pub/sub on dedicated connections with explicit, minimal config.","Document the RESP2 + token-auth incompatibility in team setup guides for Redis 6+ ACLs."],"tags":["java","redis","pubsub","resp2","authentication"],"backgroundTag":"feature-not-enabled","analyzedSha":"6dac31d4c224fb3257c216f3985340c6f500cdcb","analyzedAt":"2026-09-08T04:55:01.204Z","contentChangedAt":"2026-09-08T04:55:01.204Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}