{"record":{"id":"ddf1551a2f8115ac","repo":"nats-io/nats-server","slug":"expected-connect-packet-with-protocol-name-q-got","errorCode":null,"errorMessage":"expected connect packet with protocol name %q, got %q","messagePattern":"expected connect packet with protocol name %q, got %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/mqtt.go","lineNumber":3800,"sourceCode":"// CONNECT protocol related functions\n//\n//////////////////////////////////////////////////////////////////////////////\n\n// Parse the MQTT connect protocol\nfunc (c *client) mqttParseConnect(r *mqttReader, hasMappings bool) (byte, *mqttConnectProto, error) {\n\t// Protocol name\n\tproto, err := r.readBytes(\"protocol name\", false)\n\tif err != nil {\n\t\treturn 0, nil, err\n\t}\n\n\t// Spec [MQTT-3.1.2-1]\n\tif !bytes.Equal(proto, mqttProtoName) {\n\t\t// Check proto name against v3.1 to report better error\n\t\tif bytes.Equal(proto, mqttOldProtoName) {\n\t\t\treturn 0, nil, fmt.Errorf(\"older protocol %q not supported\", proto)\n\t\t}\n\t\treturn 0, nil, fmt.Errorf(\"expected connect packet with protocol name %q, got %q\", mqttProtoName, proto)\n\t}\n\n\t// Protocol level\n\tlevel, err := r.readByte(\"protocol level\")\n\tif err != nil {\n\t\treturn 0, nil, err\n\t}\n\t// Spec [MQTT-3.1.2-2]\n\tif level != mqttProtoLevel {\n\t\treturn mqttConnAckRCUnacceptableProtocolVersion, nil, fmt.Errorf(\"unacceptable protocol version of %v\", level)\n\t}\n\n\tcp := &mqttConnectProto{}\n\t// Connect flags\n\tcp.flags, err = r.readByte(\"flags\")\n\tif err != nil {\n\t\treturn 0, nil, err\n\t}","sourceCodeStart":3782,"sourceCodeEnd":3818,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/mqtt.go#L3782-L3818","documentation":"MQTT CONNECT parser (mqttParseConnect) guard: the protocol name field of the fixed header is not the expected \"MQTT\" string (spec MQTT-3.1.2-1). The v3.1 name \"MQIsdp\" is detected separately for a friendlier message; anything else lands here, so the client is likely not speaking MQTT at all.","triggerScenarios":"Thrown at server/mqtt.go:3800 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the client is an MQTT client connecting to the MQTT port","Upgrade MQTT 3.1 clients (MQIsdp) to MQTT 3.1.1/5","Check for TLS/plain-text port mismatches garbling the first bytes"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}