{"record":{"id":"0a6610d8f222f409","repo":"apache/shardingsphere","slug":"can-not-find-s-in-postgresql-command-packet-typ","errorCode":null,"errorMessage":"Can not find `%s` in PostgreSQL command packet type.","messagePattern":"Can not find `(.+?)` in PostgreSQL command packet type\\.","errorType":"exception","errorClass":"PostgreSQLProtocolException","httpStatus":null,"severity":"error","filePath":"database/protocol/dialect/postgresql/src/main/java/org/apache/shardingsphere/database/protocol/postgresql/packet/command/PostgreSQLCommandPacketType.java","lineNumber":76,"sourceCode":"    private static final Set<PostgreSQLCommandPacketType> EXTENDED_PROTOCOL_PACKET_TYPES = EnumSet.of(\n            PARSE_COMMAND, BIND_COMMAND, DESCRIBE_COMMAND, EXECUTE_COMMAND, SYNC_COMMAND, CLOSE_COMMAND, FLUSH_COMMAND);\n    \n    private final char value;\n    \n    /**\n     * Value of integer.\n     *\n     * @param value integer value\n     * @return command packet type enum\n     * @throws PostgreSQLProtocolException PostgreSQL protocol exception\n     */\n    public static PostgreSQLCommandPacketType valueOf(final int value) {\n        for (PostgreSQLCommandPacketType each : values()) {\n            if (value == each.value) {\n                return each;\n            }\n        }\n        throw new PostgreSQLProtocolException(\"Can not find `%s` in PostgreSQL command packet type.\", value);\n    }\n    \n    /**\n     * Check if the packet type is extended protocol packet type.\n     *\n     * @param commandPacketType command packet type\n     * @return is extended protocol packet type\n     */\n    public static boolean isExtendedProtocolPacketType(final CommandPacketType commandPacketType) {\n        return EXTENDED_PROTOCOL_PACKET_TYPES.contains(commandPacketType);\n    }\n}\n","sourceCodeStart":58,"sourceCodeEnd":89,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/database/protocol/dialect/postgresql/src/main/java/org/apache/shardingsphere/database/protocol/postgresql/packet/command/PostgreSQLCommandPacketType.java#L58-L89","documentation":"Thrown by PostgreSQLCommandPacketType.valueOf(int) when the leading byte of a command message does not match any known PostgreSQL command tag (Q, P, B, D, E, S, etc.). The value is matched against registered enum codes; failure means the byte stream does not start with a valid command tag — usually a desynchronized, TLS-garbled, or non-PostgreSQL connection.","triggerScenarios":"valueOf() receives a byte that is not a registered command tag — e.g. an SSLRequest/GSSENCRequest negotiation byte interpreted as a command, a TLS handshake read as plaintext, or HTTP traffic hitting the PostgreSQL port.","commonSituations":"sslmode misconfiguration (client expects TLS, proxy reads handshake as commands); health-check probes (HTTP/TCP) hitting the port; clients speaking a protocol version with new tags the enum lacks.","solutions":["Log the offending byte as a char/code — 'HTTP GET' bytes (0x47/0x50) or 0x16 (TLS handshake) immediately reveal wrong-protocol traffic","Align sslmode between client and proxy listener (both TLS or both plaintext)","Point health checks at a proper TCP check instead of sending HTTP to the PG port","If a legitimate new command tag from a newer PostgreSQL version, add it to the enum and report upstream"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// before dispatch, check the tag byte corresponds to a registered command type\nint tag = buffer.readUnsignedByte();\nboolean known = Arrays.stream(PostgreSQLCommandPacketType.values())\n        .anyMatch(t -> t.getValue() == tag);\nif (!known) {\n    // wrong protocol or TLS mismatch (0x16 = TLS handshake); reject the connection with a clear error\n    rejectConnection(\"unknown command tag byte: \" + tag);\n}","typeGuard":null,"tryCatchPattern":"try {\n    PostgreSQLCommandPacketType.valueOf(value);\n} catch (PostgreSQLProtocolException ex) {\n    // non-PostgreSQL/TLS/garbled input: log the byte value and close the socket; do not retry\n    connection.close();\n    log.info(\"rejected non-protocol connection: {}\", ex.getMessage());\n}","preventionTips":["Match sslmode between client and listener before connecting","Keep HTTP health checks off the PostgreSQL port; use TCP-level checks","Reject SSLRequest/GSSENCRequest negotiation bytes in the startup path, not the command dispatcher"],"tags":["postgresql","protocol","command-type","tls","wrong-protocol"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}