{"record":{"id":"e8435f98311e8f1e","repo":"alibaba/canal","slug":"unexpected-packet-type-when-ack-is-expected","errorCode":null,"errorMessage":"unexpected packet type when ack is expected","messagePattern":"unexpected packet type when ack is expected","errorType":"exception","errorClass":"CanalClientException","httpStatus":null,"severity":"error","filePath":"admin/admin-web/src/main/java/com/alibaba/otter/canal/admin/connector/SimpleAdminConnector.java","lineNumber":102,"sourceCode":"                // encode passwd\n                newPasswd = SecurityUtil.byte2HexStr(SecurityUtil.scramble411(passwd.getBytes(), seed.toByteArray()));\n            }\n\n            ClientAuth ca = ClientAuth.newBuilder()\n                .setUsername(user != null ? user : \"\")\n                .setPassword(ByteString.copyFromUtf8(newPasswd != null ? newPasswd : \"\"))\n                .setNetReadTimeout(idleTimeout)\n                .setNetWriteTimeout(idleTimeout)\n                .build();\n            writeWithHeader(Packet.newBuilder()\n                .setType(PacketType.CLIENTAUTHENTICATION)\n                .setBody(ca.toByteString())\n                .build()\n                .toByteArray());\n            //\n            Packet ack = Packet.parseFrom(readNextPacket());\n            if (ack.getType() != PacketType.ACK) {\n                throw new CanalClientException(\"unexpected packet type when ack is expected\");\n            }\n\n            Ack ackBody = Ack.parseFrom(ack.getBody());\n            if (ackBody.getCode() > 0) {\n                throw new ServiceException(\"something goes wrong when doing authentication: \" + ackBody.getMessage());\n            }\n\n            connected = true;\n        } catch (IOException | NoSuchAlgorithmException e) {\n            throw new ServiceException(e);\n        }\n    }\n\n    @Override\n    public void disconnect() throws ServiceException {\n        if (!connected) {\n            return;\n        }","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/alibaba/canal/blob/87be50e87686a3e8af08c368d0e1ffd1f59eb04a/admin/admin-web/src/main/java/com/alibaba/otter/canal/admin/connector/SimpleAdminConnector.java#L84-L120","documentation":"Thrown after the client sends a CLIENTAUTHENTICATION packet: the server reply is parsed as an Ack packet but its type is not PacketType.ACK, meaning the auth response is malformed or the server sent an unexpected message.","triggerScenarios":"After writeWithHeader(CLIENTAUTHENTICATION), readNextPacket() returns a Packet whose type != ACK. The server rejected/redirected the flow or sent an error in a non-ACK envelope.","commonSituations":"Server-side auth failure returned as a non-ACK packet; mid-handshake disconnect then reconnect; protocol version mismatch surfacing later than the handshake; network corruption truncating the packet.","solutions":["Confirm credentials (user/passwd) match the server config.","Ensure admin and server versions match (protocol expects ACK after CLIENTAUTHENTICATION).","Inspect server-side logs for the auth attempt to see what packet type it actually returned.","Verify network integrity (no truncating proxy) between admin web and server."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    connector.connect(); // triggers CLIENTAUTHENTICATION + ACK read\n} catch (CanalClientException e) {\n    if (e.getMessage().contains(\"unexpected packet type when ack\")) {\n        // inspect server logs; reconnect; align versions\n    }\n    throw e;\n}","preventionTips":["Verify credentials match before relying on the auth round-trip.","Keep the admin<->server versions aligned so ACK is the expected reply type.","Ensure no intermediary truncates the auth response packet."],"tags":["network","auth","protocol","canal-admin"],"backgroundTag":null,"analyzedSha":"87be50e87686a3e8af08c368d0e1ffd1f59eb04a","analyzedAt":"2026-08-14T04:30:11.918Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}