{"record":{"id":"918f210e83510d63","repo":"redis/jedis","slug":"unknown-message-type-firstobj","errorCode":null,"errorMessage":"Unknown message type: <firstObj>","messagePattern":"Unknown message type: <firstObj>","errorType":"exception","errorClass":"JedisException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/JedisPubSubBase.java","lineNumber":144,"sourceCode":"    } finally {\n      authenticator.client.setActiveSubscription(false);\n      authenticator.client.rollbackTimeout();\n    }\n  }\n\n  protected abstract T encode(byte[] raw);\n\n  //  private void process(Client client) {\n  private void process() {\n\n    do {\n      Object reply = authenticator.client.getUnflushedObject();\n\n      if (reply instanceof List) {\n        List<Object> listReply = (List<Object>) reply;\n        final Object firstObj = listReply.get(0);\n        if (!(firstObj instanceof byte[])) {\n          throw new JedisException(\"Unknown message type: \" + firstObj);\n        }\n        final byte[] resp = (byte[]) firstObj;\n        if (Arrays.equals(SUBSCRIBE.getRaw(), resp)) {\n          subscribedChannels = ((Long) listReply.get(2)).intValue();\n          final byte[] bchannel = (byte[]) listReply.get(1);\n          final T enchannel = (bchannel == null) ? null : encode(bchannel);\n          onSubscribe(enchannel, subscribedChannels);\n        } else if (Arrays.equals(UNSUBSCRIBE.getRaw(), resp)) {\n          subscribedChannels = ((Long) listReply.get(2)).intValue();\n          final byte[] bchannel = (byte[]) listReply.get(1);\n          final T enchannel = (bchannel == null) ? null : encode(bchannel);\n          onUnsubscribe(enchannel, subscribedChannels);\n        } else if (Arrays.equals(MESSAGE.getRaw(), resp)) {\n          final byte[] bchannel = (byte[]) listReply.get(1);\n          final Object mesg = listReply.get(2);\n          final T enchannel = (bchannel == null) ? null : encode(bchannel);\n          if (mesg instanceof List) {\n            ((List<byte[]>) mesg).forEach(bmesg -> onMessage(enchannel, encode(bmesg)));","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/JedisPubSubBase.java#L126-L162","documentation":"During the subscribe loop, JedisPubSubBase.process reads each pub/sub reply as a list whose first element must be the command name as bytes (e.g. 'subscribe', 'message', 'pong'). If the first element of a list reply is not a byte[], the reply does not conform to the RESP2 pub/sub message layout, and this JedisException ('Unknown message type: ...') is thrown (JedisPubSubBase.java:144).","triggerScenarios":"process() (via proceed/proceedWithPatterns) receives a list-typed reply whose element 0 is not a byte[] — e.g. a RESP3 push/other message shape, an error object, or a non-pub/sub reply interleaved on the connection.","commonSituations":"Mixing regular commands and pub/sub on the same connection, RESP3 protocol where replies arrive as push types not matching the expected layout, or server/proxy versions emitting non-standard pub/sub payloads.","solutions":["Use a dedicated connection for pub/sub (do not share with normal commands).","Ensure protocol matches expectations (RESP2 for classic pub/sub semantics, or upgrade Jedis for RESP3 push handling).","Check for intermediaries (proxies, RESP translators) that alter pub/sub reply format; capture the printed firstObj to identify the unexpected type."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// before subscribing, verify connection is exclusive to pub/sub\nif (!jedis.getConnection().equals(pubSubConnection)) {\n  throw new IllegalStateException(\"pub/sub requires a dedicated connection\");\n}","typeGuard":"if (reply instanceof java.util.List\n    && !((java.util.List<?>) reply).isEmpty()\n    && ((java.util.List<?>) reply).get(0) instanceof byte[]) {\n  // valid pub/sub message layout\n}","tryCatchPattern":"try {\n  pubSub.proceed(jedis, channel);\n} catch (JedisException e) {\n  if (e.getMessage().startsWith(\"Unknown message type:\")) {\n    // close connection; reopen on dedicated pub/sub connection\n  }\n}","preventionTips":["Use one connection exclusively for pub/sub; never share with regular commands.","Match the pub/sub API to the protocol/feature used (plain vs sharded pub/sub).","Log the offending firstObj value to identify non-standard replies from proxies/modules."],"tags":["java","redis","pubsub","protocol","unexpected-message"],"backgroundTag":"unexpected-response-shape","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"}