MyCATApache/Mycat-Server · error · RuntimeException
Unknown packet
Error message
Unknown packet
What it means
PacketUtils.parsePacket(byte[], int) parses a stream of PostgreSQL backend messages by their leading type byte, dispatching to parsers like AuthenticationRequest, DataRow, CopyOutResponse, ParseComplete. A type byte with no case in the switch hits default and throws RuntimeException("Unknown packet").
Solutions
- Add a case for the unknown type byte (from the MyCat log / PG protocol docs) parsing the corresponding packet class
- Upgrade MyCat to a version with a more complete PG packet parser
- Patch parsePacket to skip unknown message types gracefully using pg.getLength() instead of throwing
- Avoid triggering paths that emit unhandled messages (e.g. disable client-side notices, avoid LISTEN/NOTIFY through MyCat)
Example fix
// before
default:
throw new RuntimeException("Unknown packet");
// after
case 'S':
pg = ParameterStatus.parse(bytes, offset);
break;
default:
LOGGER.warn("Unknown packet type: " + (char) bytes[offset]);
break; Defensive patterns
Strategy: try-catch
Try / catch
try { packets = PacketUtils.parsePacket(bytes, offset); } catch (RuntimeException e) { if ("Unknown packet".equals(e.getMessage())) { /* log first type byte, skip or upgrade parser */ } else { throw e; } } Prevention
- Route only message types the parser knows through MyCat PG backend
- Suppress server notices and avoid LISTEN/NOTIFY via MyCat
- Log the unknown type byte to extend the parser quickly
When it happens
Trigger: The PostgreSQL server sends a message type (e.g. 'N' NOTICE, 'S' ParameterStatus, 'K' BackendKeyData, 'A' NotificationResponse, 'G' CopyInResponse, extended-protocol frames) that this byte[]-based switch does not handle.
Common situations: PG servers emitting frequent notices/parameter-status updates; applications using LISTEN/NOTIFY; extended query protocol (Parse/Bind) sessions; mismatched PG server version emitting messages the old MyCat parser lacks.
Related errors
- the select proess err ,the SelectResponse is empty
- Tried to send an out-of-range integer as a 2-byte value
- not a query sql statement
- Unknown Packet!
- unknown status!
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/9adb245f84e964a5.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/backend/postgresql/utils/PacketUtils.java:75
case 'D':
pg = DataRow.parse(bytes, offset);
break;
case 'I':
pg = EmptyQueryResponse.parse(bytes, offset);
break;
case 'G':
pg = CopyInResponse.parse(bytes, offset);
break;
case 'H':
pg = CopyOutResponse.parse(bytes, offset);
break;
case '1':
pg = ParseComplete.parse(bytes, offset);
break;
default:
throw new RuntimeException("Unknown packet");
}
if (pg != null) {
offset = offset + pg.getLength() + 1;
pgs.add(pg);
}
}
return pgs;
}
@Deprecated
private static List<PostgreSQLPacket> parsePacket(byte[] bytes, int offset,
int readLength) throws IOException {
List<PostgreSQLPacket> pgs = new ArrayList<>();
while (offset < readLength) {
char MAKE = (char) bytes[offset];
PostgreSQLPacket pg = null;
switch (MAKE) {View on GitHub (pinned to 65f8d8beb7)