{"record":{"id":"17a68fc0cc6f9b70","repo":"alibaba/canal","slug":"unexpected-packet-type-when-ack-is-expected-17a68f","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":"client/src/main/java/com/alibaba/otter/canal/client/impl/SimpleCanalConnector.java","lineNumber":188,"sourceCode":"                // encode passwd\n                newPasswd = SecurityUtil.byte2HexStr(SecurityUtil.scramble411(password.getBytes(), seed.toByteArray()));\n            }\n\n            ClientAuth ca = ClientAuth.newBuilder()\n                .setUsername(username != null ? username : \"\")\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.getErrorCode() > 0) {\n                throw new CanalClientException(\"something goes wrong when doing authentication: \"\n                                               + ackBody.getErrorMessage());\n            }\n\n            connected = true;\n            return new InetSocketAddress(channel.socket().getLocalAddress(), channel.socket().getLocalPort());\n        } catch (IOException | NoSuchAlgorithmException e) {\n            throw new CanalClientException(e);\n        }\n    }\n\n    private void doDisconnect() throws CanalClientException {\n        if (readableChannel != null) {\n            quietlyClose(readableChannel);","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/alibaba/canal/blob/87be50e87686a3e8af08c368d0e1ffd1f59eb04a/client/src/main/java/com/alibaba/otter/canal/client/impl/SimpleCanalConnector.java#L170-L206","documentation":"Error \"unexpected packet type when ack is expected\" thrown in alibaba/canal.","triggerScenarios":"Thrown at client/src/main/java/com/alibaba/otter/canal/client/impl/SimpleCanalConnector.java:188 when the library encounters an invalid state.","commonSituations":"Ack expected but another packet type arrived. Discard the connection after logging the packet type; continuing on a desynchronized stream corrupts batch tracking.","solutions":["Ensure getWithoutAck() and ack() calls are not interleaved concurrently from multiple threads on the same connector; the protocol is strictly request-response.","Reconnect the connector and re-subscribe if the stream became desynchronized, then resume from the last acked position."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"87be50e87686a3e8af08c368d0e1ffd1f59eb04a","analyzedAt":"2026-08-14T04:30:11.918Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}